Re: [PATCH 2/3] thermal: mediatek: Add LVTS drivers for SoC theraml zones

2020-12-06 Thread Hsin-Yi Wang
>
> Add a LVTS (Low voltage thermal sensor) driver to report junction
> temperatures in Mediatek SoC and register the maximum temperature
> of sensors and each sensor as a thermal zone.
>
> Signed-off-by: Yu-Chia Chang 
> Signed-off-by: Michael Kao 
> ---
>  drivers/thermal/mediatek/Kconfig |   10 +
>  drivers/thermal/mediatek/Makefile|1 +
>  drivers/thermal/mediatek/soc_temp_lvts.c | 1293 ++
>  drivers/thermal/mediatek/soc_temp_lvts.h |  312 ++
>  4 files changed, 1616 insertions(+)
>  create mode 100644 drivers/thermal/mediatek/soc_temp_lvts.c
>  create mode 100644 drivers/thermal/mediatek/soc_temp_lvts.h
>
> diff --git a/drivers/thermal/mediatek/Kconfig 
> b/drivers/thermal/mediatek/Kconfig
> index 0351e73170b7..d716d0372e1e 100644
> --- a/drivers/thermal/mediatek/Kconfig
> +++ b/drivers/thermal/mediatek/Kconfig
> @@ -20,4 +20,14 @@ config MTK_SOC_THERMAL
>   configures thermal controllers to collect temperature
>   via AUXADC interface.
>
> +config MTK_SOC_THERMAL_LVTS
> +tristate "LVTS (Low voltage thermal sensor) driver for Mediatek SoCs"
> +depends on HAS_IOMEM
> +depends on NVMEM
> +depends on RESET_TI_SYSCON
> +help
> +  Enable this option if you want to get SoC temperature
> +  information for Mediatek platforms. This driver
> +  configures LVTS thermal controllers to collect temperatures
> +  via Analog Serial Interface(ASIF).
>  endif
> diff --git a/drivers/thermal/mediatek/Makefile 
> b/drivers/thermal/mediatek/Makefile
> index f75313ddce5e..16ce166e5916 100644
> --- a/drivers/thermal/mediatek/Makefile
> +++ b/drivers/thermal/mediatek/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_MTK_SOC_THERMAL)  += soc_temp.o
> +obj-$(CONFIG_MTK_SOC_THERMAL_LVTS) += soc_temp_lvts.o
> diff --git a/drivers/thermal/mediatek/soc_temp_lvts.c 
> b/drivers/thermal/mediatek/soc_temp_lvts.c
> new file mode 100644
> index ..1a608870c151
> --- /dev/null
> +++ b/drivers/thermal/mediatek/soc_temp_lvts.c
> @@ -0,0 +1,1293 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2020 MediaTek Inc.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "soc_temp_lvts.h"

sort headers

> +
> +/*==
> + * Definition or macro function
> + *==
> + */
> +#define STOP_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x00)
> +#define SET_RG_TSFM_LPDLY_V4 (DEVICE_WRITE | RG_TSFM_CTRL_4 << 8 | 0xA6)
> +#define SET_COUNTING_WINDOW_20US1_V4 (DEVICE_WRITE | RG_TSFM_CTRL_2 << 8 | 
> 0x00)
> +#define SET_COUNTING_WINDOW_20US2_V4 (DEVICE_WRITE | RG_TSFM_CTRL_1 << 8 | 
> 0x20)
> +#define TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_2 << 
> 8 | 0x84)
> +#define TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_4 << 
> 8 | 0x7C)
> +#define SET_TS_RSV_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_1 << 8 | 0x8D)
> +#define SET_TS_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xF4)
> +#define TOGGLE_RG_TSV2F_VCO_RST1_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 
> 0xFC)
> +#define TOGGLE_RG_TSV2F_VCO_RST2_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 
> 0xF4)
> +
> +#define SET_LVTS_AUTO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_6 << 8 | 0x01)
> +#define SELECT_SENSOR_RCK_V4(id) (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | (id))
> +#define SET_DEVICE_SINGLE_MODE_V4 (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0x78)
> +#define KICK_OFF_RCK_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x02)
> +#define SET_SENSOR_NO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | 0x10)
> +#define SET_DEVICE_LOW_POWER_SINGLE_MODE_V4 (DEVICE_WRITE | RG_TSFM_CTRL_3 
> << 8| 0xB8)
> +
> +#define ENABLE_FEATURE(feature)(lvts_data->feature_bitmap |= 
> (feature))
> +#define DISABLE_FEATURE(feature)   (lvts_data->feature_bitmap &= 
> (~(feature)))
> +#define IS_ENABLE(feature) (lvts_data->feature_bitmap & 
> (feature))
> +
> +#define DISABLE_THERMAL_HW_REBOOT (-274000)
> +
> +#define CLOCK_26MHZ_CYCLE_NS   (38)
> +#define BUS_ACCESS_US  (2)
> +
> +#define FEATURE_DEVICE_AUTO_RCK(BIT(0))
> +#define FEATURE_CK26M_ACTIVE   (BIT(1))
> +#define CK26M_ACTIVE   (((lvts_data->feature_bitmap & FEATURE_CK26M_ACTIVE)  
>   \
> +   ? 1 : 0) << 30)
> +#define GET_BASE_ADDR(tc_id)   \
> +   (lvts_data->domain[lvts_data->tc[tc_id].domain_index].base  \
> +   + lvts_data->tc[tc_id].addr_offset)
> +
> +#define SET_TC_SPEED_IN_US(pu, gd, fd, sd) \
> +   {   \
> +   .period_unit = (((pu) * 1000) / (256 * 
> CLOCK_26MHZ_CYCLE_NS)),  \
> +   .group_interval_delay = ((gd) / (pu)),  \
> +   .filter_interval_delay = ((fd) / 

[PATCH] drm/mediatek: mtk_dpi: Create connector for bridges

2020-12-03 Thread Hsin-Yi Wang
Similar to a9d9fea74be2 ("drm/mediatek: mtk_dsi: Create connector for bridges"):

Use the drm_bridge_connector helper to create a connector for pipelines
that use drm_bridge. This allows splitting connector operations across
multiple bridges when necessary, instead of having the last bridge in
the chain creating the connector and handling all connector operations
internally.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/mediatek/mtk_dpi.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c 
b/drivers/gpu/drm/mediatek/mtk_dpi.c
index 52f11a63a330..189377e342fa 100644
--- a/drivers/gpu/drm/mediatek/mtk_dpi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,6 +67,7 @@ struct mtk_dpi {
struct drm_encoder encoder;
struct drm_bridge bridge;
struct drm_bridge *next_bridge;
+   struct drm_connector *connector;
void __iomem *regs;
struct device *dev;
struct clk *engine_clk;
@@ -603,12 +605,21 @@ static int mtk_dpi_bind(struct device *dev, struct device 
*master, void *data)
 
dpi->encoder.possible_crtcs = 
mtk_drm_find_possible_crtc_by_comp(drm_dev, dpi->ddp_comp);
 
-   ret = drm_bridge_attach(>encoder, >bridge, NULL, 0);
+   ret = drm_bridge_attach(>encoder, >bridge, NULL,
+   DRM_BRIDGE_ATTACH_NO_CONNECTOR);
if (ret) {
dev_err(dev, "Failed to attach bridge: %d\n", ret);
goto err_cleanup;
}
 
+   dpi->connector = drm_bridge_connector_init(drm_dev, >encoder);
+   if (IS_ERR(dpi->connector)) {
+   dev_err(dev, "Unable to create bridge connector\n");
+   ret = PTR_ERR(dpi->connector);
+   goto err_cleanup;
+   }
+   drm_connector_attach_encoder(dpi->connector, >encoder);
+
dpi->bit_num = MTK_DPI_OUT_BIT_NUM_8BITS;
dpi->channel_swap = MTK_DPI_OUT_CHANNEL_SWAP_RGB;
dpi->yc_map = MTK_DPI_OUT_YC_MAP_RGB;
-- 
2.29.2.576.ga3fc446d84-goog



Re: [v5 2/3] arm64: dts: mt8183: Configure CPU cooling

2020-11-24 Thread Hsin-Yi Wang
On Tue, Oct 13, 2020 at 6:24 PM Michael Kao  wrote:
>
> From: Matthias Kaehlcke 
>
> Add two passive trip points at 68°C and 80°C for the CPU temperature.
>
> Signed-off-by: Matthias Kaehlcke 
> Signed-off-by: Michael Kao 

Tested-by: Hsin-Yi Wang 

> ---
>  arch/arm64/boot/dts/mediatek/mt8183.dtsi | 56 
>  1 file changed, 56 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> index 1cd093cf33f3..0614f18a1ea2 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> @@ -10,6 +10,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "mt8183-pinfunc.h"
>
>  / {
> @@ -450,6 +451,61 @@
> polling-delay = <500>;
> thermal-sensors = < 0>;
> sustainable-power = <5000>;
> +
> +   trips {
> +   threshold: trip-point@0 {
> +   temperature = <68000>;
> +   hysteresis = <2000>;
> +   type = "passive";
> +   };
> +
> +   target: trip-point@1 {
> +   temperature = <8>;
> +   hysteresis = <2000>;
> +   type = "passive";
> +   };
> +
> +   cpu_crit: cpu-crit {
> +   temperature = <115000>;
> +   hysteresis = <2000>;
> +   type = "critical";
> +   };
> +   };
> +
> +   cooling-maps {
> +   map0 {
> +   trip = <>;
> +   cooling-device = <
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>;
> +   contribution = <3072>;
> +   };
> +   map1 {
> +   trip = <>;
> +   cooling-device = <
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>,
> +<
> +   THERMAL_NO_LIMIT
> +   THERMAL_NO_LIMIT>;
> +   contribution = <1024>;
> +   };
> +   };
> };
>
> /* The tzts1 ~ tzts6 don't need to polling */
> --
> 2.18.0


Re: [v5 1/3] arm64: dts: mt8183: add thermal zone node

2020-11-24 Thread Hsin-Yi Wang
On Tue, Oct 13, 2020 at 6:24 PM Michael Kao  wrote:
>
> From: "Michael.Kao" 
>
> Add thermal zone node to Mediatek MT8183 dts file.
>
> Evaluate the thermal zone every 500ms while not cooling
> and every 100ms when passive cooling is performed.
>
> Signed-off-by: Matthias Kaehlcke 
> Signed-off-by: Michael Kao 
> ---
>  arch/arm64/boot/dts/mediatek/mt8183.dtsi | 84 
>  1 file changed, 84 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> index 8fed72bb35d7..1cd093cf33f3 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> @@ -430,6 +430,86 @@
> status = "disabled";
> };
>
> +   thermal: thermal@1100b000 {
> +   #thermal-sensor-cells = <1>;
> +   compatible = "mediatek,mt8183-thermal";
> +   reg = <0 0x1100b000 0 0x1000>;
> +   clocks = < CLK_INFRA_THERM>,
> +< CLK_INFRA_AUXADC>;
> +   clock-names = "therm", "auxadc";
> +   resets = <  MT8183_INFRACFG_AO_THERM_SW_RST>;

According to binding document[1], interrupts is required.
interrupts = <0 76 IRQ_TYPE_LEVEL_LOW>;

[1] 
https://elixir.bootlin.com/linux/v5.10-rc3/source/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt#L18

> +   mediatek,auxadc = <>;
> +   mediatek,apmixedsys = <>;
> +   nvmem-cells = <_calibration>;
> +   nvmem-cell-names = "calibration-data";
> +   };
> +
> +   thermal-zones {
> +   cpu_thermal: cpu_thermal {
> +   polling-delay-passive = <100>;
> +   polling-delay = <500>;
> +   thermal-sensors = < 0>;
> +   sustainable-power = <5000>;
> +   };
> +
> +   /* The tzts1 ~ tzts6 don't need to polling */
> +   /* The tzts1 ~ tzts6 don't need to thermal throttle */
> +
> +   tzts1: tzts1 {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 1>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +
> +   tzts2: tzts2 {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 2>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +
> +   tzts3: tzts3 {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 3>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +
> +   tzts4: tzts4 {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 4>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +
> +   tzts5: tzts5 {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 5>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +
> +   tztsABB: tztsABB {
> +   polling-delay-passive = <0>;
> +   polling-delay = <0>;
> +   thermal-sensors = < 6>;
> +   sustainable-power = <5000>;
> +   trips {};
> +   cooling-maps {};
> +   };
> +   };
> +
> i2c3: i2c@1100f000 {
> compatible = "mediatek,mt8183-i2c";
> reg = <0 0x1100f000 0 0x1000>,
> @@ -675,6 +755,10 @@
> compatible = "mediatek,mt8183-efuse",
>  "mediatek,efuse";
> 

[PATCH] arm64: dts: mt8183: Add pwm and backlight node

2020-11-23 Thread Hsin-Yi Wang
Add pwm to mt8183 and backlight to mt8183-kukui.

Signed-off-by: Hsin-Yi Wang 
---
 .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 28 +++
 arch/arm64/boot/dts/mediatek/mt8183.dtsi  | 10 +++
 2 files changed, 38 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
index 85f7c33ba4461..bf2ad1294dd30 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
@@ -19,6 +19,17 @@ chosen {
stdout-path = "serial0:115200n8";
};
 
+   backlight_lcd0: backlight_lcd0 {
+   compatible = "pwm-backlight";
+   pwms = < 0 50>;
+   power-supply = <_pp5000>;
+   enable-gpios = < 176 0>;
+   brightness-levels = <0 1023>;
+   num-interpolated-steps = <1023>;
+   default-brightness-level = <576>;
+   status = "okay";
+   };
+
memory@4000 {
device_type = "memory";
reg = <0 0x4000 0 0x8000>;
@@ -536,6 +547,17 @@ pins_clk {
};
};
 
+   pwm0_pin_default: pwm0_pin_default {
+   pins1 {
+   pinmux = ;
+   output-high;
+   bias-pull-up;
+   };
+   pins2 {
+   pinmux = ;
+   };
+   };
+
scp_pins: scp {
pins_scp_uart {
pinmux = ,
@@ -670,6 +692,12 @@ pins_wifi_wakeup {
};
 };
 
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pin_default>;
+};
+
  {
status = "okay";
pinctrl-names = "default";
diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 08a914d3a6435..a974bad899365 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -479,6 +479,16 @@ spi0: spi@1100a000 {
status = "disabled";
};
 
+   pwm0: pwm@1100e000 {
+   compatible = "mediatek,mt8183-disp-pwm";
+   reg = <0 0x1100e000 0 0x1000>;
+   interrupts = ;
+   #pwm-cells = <2>;
+   clocks = < CLK_TOP_MUX_DISP_PWM>,
+   < CLK_INFRA_DISP_PWM>;
+   clock-names = "main", "mm";
+   };
+
i2c3: i2c@1100f000 {
compatible = "mediatek,mt8183-i2c";
reg = <0 0x1100f000 0 0x1000>,
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH v2 2/2] drm/bridge: anx7625: disable regulators when power off

2020-11-22 Thread Hsin-Yi Wang
When suspending the driver, anx7625_power_standby() will be called to
turn off reset-gpios and enable-gpios. However, power supplies are not
disabled. To save power, the driver can get the power supply regulators
and turn off them in anx7625_power_standby().

Signed-off-by: Hsin-Yi Wang 
---
Change:
v2: none
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 25 +++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 65cc05982f82..eb9c4cc2504a 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -875,12 +876,20 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
 static void anx7625_power_on(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
+   int ret;
 
if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
return;
}
 
+   ret = regulator_bulk_enable(ARRAY_SIZE(ctx->pdata.supplies),
+   ctx->pdata.supplies);
+   if (ret < 0) {
+   DRM_DEV_DEBUG_DRIVER(dev, "cannot enable regulators %d\n", ret);
+   return;
+   }
+
/* Power on pin enable */
gpiod_set_value(ctx->pdata.gpio_p_on, 1);
usleep_range(1, 11000);
@@ -894,6 +903,7 @@ static void anx7625_power_on(struct anx7625_data *ctx)
 static void anx7625_power_standby(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
+   int ret;
 
if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
@@ -904,6 +914,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx)
usleep_range(1000, 1100);
gpiod_set_value(ctx->pdata.gpio_p_on, 0);
usleep_range(1000, 1100);
+
+   ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies),
+ctx->pdata.supplies);
+   if (ret < 0)
+   DRM_DEV_DEBUG_DRIVER(dev, "cannot disable regulators %d\n", 
ret);
+
DRM_DEV_DEBUG_DRIVER(dev, "power down\n");
 }
 
@@ -1742,6 +1758,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
platform->client = client;
i2c_set_clientdata(client, platform);
 
+   pdata->supplies[0].supply = "vdd10";
+   pdata->supplies[1].supply = "vdd18";
+   pdata->supplies[2].supply = "vdd33";
+   ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret);
+   return ret;
+   }
anx7625_init_gpio(platform);
 
atomic_set(>power_status, 0);
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 193ad86c5450..e4a086b3a3d7 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -350,6 +350,7 @@ struct s_edid_data {
 struct anx7625_platform_data {
struct gpio_desc *gpio_p_on;
struct gpio_desc *gpio_reset;
+   struct regulator_bulk_data supplies[3];
struct drm_bridge *panel_bridge;
int intp_irq;
u32 low_power_mode;
-- 
2.29.2.454.gaff20da3a2-goog



[PATCH v2 1/2] dt-bindings: drm/bridge: anx7625: Add power supplies

2020-11-22 Thread Hsin-Yi Wang
anx7625 requires 3 power supply regulators.

Signed-off-by: Hsin-Yi Wang 
---
Change:
v2: remove maxItems for supplies
---
 .../bindings/display/bridge/analogix,anx7625.yaml | 15 +++
 1 file changed, 15 insertions(+)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index 60585a4fc22b..3ae97d9523e5 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -34,6 +34,15 @@ properties:
 description: used for reset chip control, RESET_N pin B7.
 maxItems: 1
 
+  vdd10-supply:
+description: Regulator that provides the supply 1.0V power.
+
+  vdd18-supply:
+description: Regulator that provides the supply 1.8V power.
+
+  vdd33-supply:
+description: Regulator that provides the supply 3.3V power.
+
   ports:
 type: object
 
@@ -55,6 +64,9 @@ properties:
 required:
   - compatible
   - reg
+  - vdd10-supply
+  - vdd18-supply
+  - vdd33-supply
   - ports
 
 additionalProperties: false
@@ -72,6 +84,9 @@ examples:
 reg = <0x58>;
 enable-gpios = < 45 GPIO_ACTIVE_HIGH>;
 reset-gpios = < 73 GPIO_ACTIVE_HIGH>;
+vdd10-supply = <_mipibrdg>;
+vdd18-supply = <_mipibrdg>;
+vdd33-supply = <_mipibrdg>;
 
 ports {
 #address-cells = <1>;
-- 
2.29.2.454.gaff20da3a2-goog



Re: [RESEND v7, PATCH 4/7] mtk-mmsys: add mt8183 mmsys support

2020-11-16 Thread Hsin-Yi Wang
On Sat, Aug 8, 2020 at 2:53 AM Yongqiang Niu  wrote:
>
> add mt8183 mmsys support
>
> Signed-off-by: Yongqiang Niu 
> ---
>  drivers/soc/mediatek/mmsys/Makefile   |   1 +
>  drivers/soc/mediatek/mmsys/mt8183-mmsys.c | 154 
> ++
>  drivers/soc/mediatek/mtk-mmsys.c  |   1 +
>  3 files changed, 156 insertions(+)
>  create mode 100644 drivers/soc/mediatek/mmsys/mt8183-mmsys.c
>
> diff --git a/drivers/soc/mediatek/mmsys/Makefile 
> b/drivers/soc/mediatek/mmsys/Makefile
> index 33b0dab..62cfedf 100644
> --- a/drivers/soc/mediatek/mmsys/Makefile
> +++ b/drivers/soc/mediatek/mmsys/Makefile
> @@ -1,2 +1,3 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  obj-y += mt2701-mmsys.o
> +obj-y += mt8183-mmsys.o
> diff --git a/drivers/soc/mediatek/mmsys/mt8183-mmsys.c 
> b/drivers/soc/mediatek/mmsys/mt8183-mmsys.c
> new file mode 100644
> index 000..e5170b5
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmsys/mt8183-mmsys.c
> @@ -0,0 +1,154 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Copyright (c) 2020 MediaTek Inc.
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DISP_OVL0_MOUT_EN  0xf00
> +#define DISP_OVL0_2L_MOUT_EN   0xf04
> +#define DISP_OVL1_2L_MOUT_EN   0xf08
> +#define DISP_DITHER0_MOUT_EN   0xf0c
> +#define DISP_PATH0_SEL_IN  0xf24
> +#define DISP_DSI0_SEL_IN   0xf2c
> +#define DISP_DPI0_SEL_IN   0xf30
> +#define DISP_RDMA0_SOUT_SEL_IN 0xf50
> +#define DISP_RDMA1_SOUT_SEL_IN 0xf54
> +
> +#define OVL0_MOUT_EN_OVL0_2L   BIT(4)
> +#define OVL0_2L_MOUT_EN_DISP_PATH0 BIT(0)
> +#define OVL1_2L_MOUT_EN_RDMA1  BIT(4)
> +#define DITHER0_MOUT_IN_DSI0   BIT(0)
> +#define DISP_PATH0_SEL_IN_OVL0_2L  0x1
> +#define DSI0_SEL_IN_RDMA0  0x1
> +#define DSI0_SEL_IN_RDMA1  0x3
> +#define DPI0_SEL_IN_RDMA0  0x1
> +#define DPI0_SEL_IN_RDMA1  0x2
> +#define RDMA0_SOUT_COLOR0  0x1
> +#define RDMA1_SOUT_DSI00x1
> +
> +struct mmsys_path_sel {
> +   enum mtk_ddp_comp_id cur;
> +   enum mtk_ddp_comp_id next;
> +   u32 addr;
> +   u32 val;
> +};
> +
> +static struct mmsys_path_sel mmsys_mout_en[] = {
> +   {
> +   DDP_COMPONENT_OVL0, DDP_COMPONENT_OVL_2L0,
> +   DISP_OVL0_MOUT_EN, OVL0_MOUT_EN_OVL0_2L,
> +   },
> +   {
> +   DDP_COMPONENT_OVL_2L0, DDP_COMPONENT_RDMA0,
> +   DISP_OVL0_2L_MOUT_EN, OVL0_2L_MOUT_EN_DISP_PATH0,
> +   },
> +   {
> +   DDP_COMPONENT_OVL_2L1, DDP_COMPONENT_RDMA1,
> +   DISP_OVL1_2L_MOUT_EN, OVL1_2L_MOUT_EN_RDMA1,
> +   },
> +   {
> +   DDP_COMPONENT_DITHER, DDP_COMPONENT_DSI0,
> +   DISP_DITHER0_MOUT_EN, DITHER0_MOUT_IN_DSI0,
> +   },
> +};
> +
> +static struct mmsys_path_sel mmsys_sel_in[] = {
> +   {
> +   DDP_COMPONENT_OVL_2L0, DDP_COMPONENT_RDMA0,
> +   DISP_PATH0_SEL_IN, DISP_PATH0_SEL_IN_OVL0_2L,
> +   },
> +   {
> +   DDP_COMPONENT_RDMA1, DDP_COMPONENT_DPI0,
> +   DISP_DPI0_SEL_IN, DPI0_SEL_IN_RDMA1,
> +   },
> +};
> +
> +static struct mmsys_path_sel mmsys_sout_sel[] = {
> +   {
> +   DDP_COMPONENT_RDMA0, DDP_COMPONENT_COLOR0,
> +   DISP_RDMA0_SOUT_SEL_IN, RDMA0_SOUT_COLOR0,
> +   },
> +};
> +
> +static unsigned int mtk_mmsys_ddp_mout_en(enum mtk_ddp_comp_id cur,
> + enum mtk_ddp_comp_id next,
> + unsigned int *addr)
> +{
> +   u32 i;
> +   struct mmsys_path_sel *path;
> +
> +   for (i = 0; i < ARRAY_SIZE(mmsys_mout_en); i++) {
> +   path = _mout_en[i];
> +   if (cur == path->cur && next == path->next) {
> +   *addr = path->addr;
> +   return path->val;
> +   }
> +   }
> +
> +   return 0;
> +}
> +
> +static unsigned int mtk_mmsys_ddp_sel_in(enum mtk_ddp_comp_id cur,
> +enum mtk_ddp_comp_id next,
> +unsigned int *addr)
> +{
> +   u32 i;
> +   struct mmsys_path_sel *path;
> +
> +   for (i = 0; i < ARRAY_SIZE(mmsys_sel_in); i++) {
> +   path = _sel_in[i];
> +   if (cur == path->cur && next == path->next) {
> +   *addr = path->addr;
> +   return path->val;
> +   }
> +   }
> +
> +   return 0;
> +}
> +
> +static void mtk_mmsys_ddp_sout_sel(void __iomem *config_regs,
> +  enum mtk_ddp_comp_id cur,
> +  enum mtk_ddp_comp_id next)
> +{
> +   u32 i;
> +   u32 val = 0;

This variable is unused.

> 

[PATCH 1/2] dt-bindings: drm/bridge: anx7625: Add power supplies

2020-11-12 Thread Hsin-Yi Wang
anx7625 requires 3 power supply regulators.

Signed-off-by: Hsin-Yi Wang 
---
 .../display/bridge/analogix,anx7625.yaml   | 18 ++
 1 file changed, 18 insertions(+)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index 60585a4fc22b..1aa08f10d894 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -34,6 +34,18 @@ properties:
 description: used for reset chip control, RESET_N pin B7.
 maxItems: 1
 
+  vdd10-supply:
+description: Regulator that provides the supply 1.0V power.
+maxItems: 1
+
+  vdd18-supply:
+description: Regulator that provides the supply 1.8V power.
+maxItems: 1
+
+  vdd33-supply:
+description: Regulator that provides the supply 3.3V power.
+maxItems: 1
+
   ports:
 type: object
 
@@ -55,6 +67,9 @@ properties:
 required:
   - compatible
   - reg
+  - vdd10-supply
+  - vdd18-supply
+  - vdd33-supply
   - ports
 
 additionalProperties: false
@@ -72,6 +87,9 @@ examples:
 reg = <0x58>;
 enable-gpios = < 45 GPIO_ACTIVE_HIGH>;
 reset-gpios = < 73 GPIO_ACTIVE_HIGH>;
+vdd10-supply = <_mipibrdg>;
+vdd18-supply = <_mipibrdg>;
+vdd33-supply = <_mipibrdg>;
 
 ports {
 #address-cells = <1>;
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 2/2] drm/bridge: anx7625: disable regulators when power off

2020-11-12 Thread Hsin-Yi Wang
When suspending the driver, anx7625_power_standby() will be called to
turn off reset-gpios and enable-gpios. However, power supplies are not
disabled. To save power, the driver can get the power supply regulators
and turn off them in anx7625_power_standby().

Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 25 +++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  1 +
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 65cc05982f82..eb9c4cc2504a 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -875,12 +876,20 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
 static void anx7625_power_on(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
+   int ret;
 
if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
return;
}
 
+   ret = regulator_bulk_enable(ARRAY_SIZE(ctx->pdata.supplies),
+   ctx->pdata.supplies);
+   if (ret < 0) {
+   DRM_DEV_DEBUG_DRIVER(dev, "cannot enable regulators %d\n", ret);
+   return;
+   }
+
/* Power on pin enable */
gpiod_set_value(ctx->pdata.gpio_p_on, 1);
usleep_range(1, 11000);
@@ -894,6 +903,7 @@ static void anx7625_power_on(struct anx7625_data *ctx)
 static void anx7625_power_standby(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
+   int ret;
 
if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
@@ -904,6 +914,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx)
usleep_range(1000, 1100);
gpiod_set_value(ctx->pdata.gpio_p_on, 0);
usleep_range(1000, 1100);
+
+   ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies),
+ctx->pdata.supplies);
+   if (ret < 0)
+   DRM_DEV_DEBUG_DRIVER(dev, "cannot disable regulators %d\n", 
ret);
+
DRM_DEV_DEBUG_DRIVER(dev, "power down\n");
 }
 
@@ -1742,6 +1758,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
platform->client = client;
i2c_set_clientdata(client, platform);
 
+   pdata->supplies[0].supply = "vdd10";
+   pdata->supplies[1].supply = "vdd18";
+   pdata->supplies[2].supply = "vdd33";
+   ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret);
+   return ret;
+   }
anx7625_init_gpio(platform);
 
atomic_set(>power_status, 0);
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 193ad86c5450..e4a086b3a3d7 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -350,6 +350,7 @@ struct s_edid_data {
 struct anx7625_platform_data {
struct gpio_desc *gpio_p_on;
struct gpio_desc *gpio_reset;
+   struct regulator_bulk_data supplies[3];
struct drm_bridge *panel_bridge;
int intp_irq;
u32 low_power_mode;
-- 
2.29.2.222.g5d2a92d10f8-goog



Re: [PATCH 11/12] soc: mediatek: pm-domains: Add support for mt8183

2020-09-25 Thread Hsin-Yi Wang
On Wed, Sep 16, 2020 at 8:19 PM Matthias Brugger  wrote:
>
>
>
> On 16/09/2020 11:46, Matthias Brugger wrote:
> >
> >
> > On 10/09/2020 19:28, Enric Balletbo i Serra wrote:
> >> From: Matthias Brugger 
> >>
> >> Add the needed board data to support mt8183 SoC.
> >>
> >> Signed-off-by: Matthias Brugger 
> >> Signed-off-by: Enric Balletbo i Serra 
> >> ---
> >>
> >>   drivers/soc/mediatek/mtk-pm-domains.c | 162 ++
> >>   include/linux/soc/mediatek/infracfg.h |  28 +
> >>   2 files changed, 190 insertions(+)
> >>
> >> diff --git a/drivers/soc/mediatek/mtk-pm-domains.c
> >> b/drivers/soc/mediatek/mtk-pm-domains.c
> >> index 29e88adc8ea6..aa434f616fee 100644
> >> --- a/drivers/soc/mediatek/mtk-pm-domains.c
> >> +++ b/drivers/soc/mediatek/mtk-pm-domains.c
> > [...]
> >> +/*
> >> + * MT8183 power domain support
> >> + */
> >> +static const struct scpsys_domain_data scpsys_domain_data_mt8183[] = {
> >> +[MT8183_POWER_DOMAIN_AUDIO] = {
> >> +.sta_mask = PWR_STATUS_AUDIO,
> >> +.ctl_offs = 0x0314,
> >> +.sram_pdn_bits = GENMASK(11, 8),
> >> +.sram_pdn_ack_bits = GENMASK(15, 12),
> >> +},
> >> +[MT8183_POWER_DOMAIN_CONN] = {
> >> +.sta_mask = PWR_STATUS_CONN,
> >> +.ctl_offs = 0x032c,
> >> +.sram_pdn_bits = 0,
> >> +.sram_pdn_ack_bits = 0,
> >> +.bp_infracfg = {
> >> +BUS_PROT_WR(MT8183_TOP_AXI_PROT_EN_CONN, 0x2a0, 0x2a4, 0x228),
> >
> > We have repeating values triplets for set, clear and status register in 
> > infracfg
> > and SMI.
> >
> > Weiyi can you help to get names to this registers? I wasn't able to find
> > anything in the datasheet.
>
> I think for the infracfg part I figured it out:
>
> #define INFRA_TOPAXI_PROTECTEN_SET  0x2a0
> #define INFRA_TOPAXI_PROTECTEN_CLR  0x2a4
> #define INFRA_TOPAXI_PROTECTEN_STA1 0x228
>
> #define INFRA_TOPAXI_PROTECTEN_1_SET0x2a8
> #define INFRA_TOPAXI_PROTECTEN_1_CLR0x2ac
> #define INFRA_TOPAXI_PROTECTEN_STA1_1   0x258
>
> #define INFRA_TOPAXI_PROTECTEN_MCU_SET  0x2d4
> #define INFRA_TOPAXI_PROTECTEN_MCU_CLR  0x2d8
> #define INFRA_TOPAXI_PROTECTEN_MM_STA1  0x2ec
>
> Weiyi, can you still provide the register names for the SMI?
>
> Thanks in advance!
> Matthias
>
Hi Matthias,

SMI names are
#define SMI_COMMON_CLAMP_EN 0x3c0
#define SMI_COMMON_CLAMP_EN_SET 0x3c4
#define SMI_COMMON_CLAMP_EN_CLR 0x3c8

Thanks


Re: [PATCH] arm64: dts: mt8173: elm: Fix nor_flash node property

2020-09-15 Thread Hsin-Yi Wang
On Fri, Jul 31, 2020 at 7:21 PM Enric Balletbo i Serra
 wrote:
>
> Hi Hsin-Yi,
>
> Thank you for your patch.
>
> On 27/7/20 9:41, Hsin-Yi Wang wrote:
> > bus-width and non-removable is not used by the driver.
> > max-frequency should be spi-max-frequency for flash node.
> >
> > Fixes: 689b937bedde ("arm64: dts: mediatek: add mt8173 elm and hana board")
> > Reported-by: Nicolas Boichat 
> > Signed-off-by: Hsin-Yi Wang 
>
> Reviewed-by: Enric Balletbo i Serra 
>
Gentle ping.


[PATCH v2 1/2] tty: serial: print earlycon info after match->setup

2020-09-14 Thread Hsin-Yi Wang
8250 devices may modify iotype in their own earlycon setup. For example:
8250_mtk and 8250_uniphier force iotype to be MMIO32. Print earlycon info
after match->setup to reflect actual earlycon info.

Signed-off-by: Hsin-Yi Wang 
---
Change:
v1->v2: rename function
---
 drivers/tty/serial/earlycon.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 2ae9190b64bb9..b70877932d47d 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -56,7 +56,6 @@ static void __init earlycon_init(struct earlycon_device 
*device,
 const char *name)
 {
struct console *earlycon = device->con;
-   struct uart_port *port = >port;
const char *s;
size_t len;
 
@@ -70,6 +69,12 @@ static void __init earlycon_init(struct earlycon_device 
*device,
len = s - name;
strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
earlycon->data = _console_dev;
+}
+
+static void __init earlycon_print_info(struct earlycon_device *device)
+{
+   struct console *earlycon = device->con;
+   struct uart_port *port = >port;
 
if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM16 ||
port->iotype == UPIO_MEM32 || port->iotype == UPIO_MEM32BE)
@@ -140,6 +145,7 @@ static int __init register_earlycon(char *buf, const struct 
earlycon_id *match)
 
earlycon_init(_console_dev, match->name);
err = match->setup(_console_dev, buf);
+   earlycon_print_info(_console_dev);
if (err < 0)
return err;
if (!early_console_dev.con->write)
@@ -302,6 +308,7 @@ int __init of_setup_earlycon(const struct earlycon_id 
*match,
}
earlycon_init(_console_dev, match->name);
err = match->setup(_console_dev, options);
+   earlycon_print_info(_console_dev);
if (err < 0)
return err;
if (!early_console_dev.con->write)
-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH v2 2/2] tty: serial: 8250_mtk: set regshift for mmio32

2020-09-14 Thread Hsin-Yi Wang
To use mmio32, we also need to set regshift.

Signed-off-by: Hsin-Yi Wang 
---
Change:
v1->v2: none
---
 drivers/tty/serial/8250/8250_mtk.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/serial/8250/8250_mtk.c 
b/drivers/tty/serial/8250/8250_mtk.c
index 7b0dec14c8b80..41f4120abdf29 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -669,6 +669,7 @@ static int __init early_mtk8250_setup(struct 
earlycon_device *device,
return -ENODEV;
 
device->port.iotype = UPIO_MEM32;
+   device->port.regshift = 2;
 
return early_serial8250_setup(device, NULL);
 }
-- 
2.28.0.618.gf4bc123cb7-goog



Re: [PATCH 1/2] tty: serial: print earlycon info after match->setup

2020-09-14 Thread Hsin-Yi Wang
On Tue, Sep 15, 2020 at 12:06 AM Andy Shevchenko
 wrote:
>
> On Fri, Sep 11, 2020 at 05:39:26PM +0800, Hsin-Yi Wang wrote:
> > 8250 devices may modify iotype in their own earlycon setup. For example:
> > 8250_mtk and 8250_uniphier force iotype to be MMIO32. Print earlycon info
> > after match->setup to reflect actual earlycon info.
>
> But this means you do something which user didn't ask for...
>
8250_uniphier states that it can only use mmio32
https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/tty/serial/8250/8250_uniphier.c#L46

For MTK, may be the same case. So they are set in the driver.

> > +static void __init earlycon_info(struct earlycon_device *device)
>
> Can it be earlycon_pr_info() or earlycon_print_info() ?
>
Sure. I'll send a v2.

> --
> With Best Regards,
> Andy Shevchenko
>
>


Re: [PATCH v2 1/2] arm64: dts: mt8173: Set uart to mmio32 iotype

2020-09-11 Thread Hsin-Yi Wang
On Thu, Sep 10, 2020 at 9:40 PM Hsin-Yi Wang  wrote:
>
> On Thu, Sep 10, 2020 at 6:25 PM Matthias Brugger  
> wrote:
> >
> > Hi,
> >
> > On 10/09/2020 10:43, Hsin-Yi Wang wrote:
> > > Set uart iotype to mmio32 to make earlycon work with stdout-path.
> > >
> > > Signed-off-by: Hsin-Yi Wang 
> > > ---
> > >   arch/arm64/boot/dts/mediatek/mt8173.dtsi | 8 
> > >   1 file changed, 8 insertions(+)
> > >
> > > diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
> > > b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > > index 5e046f9d48ce9..ca6ea71f5f435 100644
> > > --- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > > +++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > > @@ -613,6 +613,8 @@ uart0: serial@11002000 {
> > >   interrupts = ;
> > >   clocks = < CLK_PERI_UART0_SEL>, < 
> > > CLK_PERI_UART0>;
> > >   clock-names = "baud", "bus";
> > > + reg-io-width = <4>;
> >
> > Why do we need that, we have
> > device->port.iotype = UPIO_MEM32;
> > in early_mtk8250_setup(). That should do the job already.
> >
> >
>
> But if we don't change in dts, we would see
> [0.00] earlycon: mtk8250 at MMIO 0x11002000 (options 
> '115200n8')
> instead of
> [0.00] earlycon: mtk8250 at MMIO32 0x11002000 (options
> '115200n8')
>
> Perhaps we should move the pr_info part in earlycon_init() after
> match->setup(). Since setup may change iotype. What do you think?
>

The series is sent here: https://lore.kernel.org/patchwork/patch/1304227/

Thanks.


[PATCH 1/2] tty: serial: print earlycon info after match->setup

2020-09-11 Thread Hsin-Yi Wang
8250 devices may modify iotype in their own earlycon setup. For example:
8250_mtk and 8250_uniphier force iotype to be MMIO32. Print earlycon info
after match->setup to reflect actual earlycon info.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/tty/serial/earlycon.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
index 2ae9190b64bb9..22f0876f72d49 100644
--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -56,7 +56,6 @@ static void __init earlycon_init(struct earlycon_device 
*device,
 const char *name)
 {
struct console *earlycon = device->con;
-   struct uart_port *port = >port;
const char *s;
size_t len;
 
@@ -70,6 +69,12 @@ static void __init earlycon_init(struct earlycon_device 
*device,
len = s - name;
strlcpy(earlycon->name, name, min(len + 1, sizeof(earlycon->name)));
earlycon->data = _console_dev;
+}
+
+static void __init earlycon_info(struct earlycon_device *device)
+{
+   struct console *earlycon = device->con;
+   struct uart_port *port = >port;
 
if (port->iotype == UPIO_MEM || port->iotype == UPIO_MEM16 ||
port->iotype == UPIO_MEM32 || port->iotype == UPIO_MEM32BE)
@@ -140,6 +145,7 @@ static int __init register_earlycon(char *buf, const struct 
earlycon_id *match)
 
earlycon_init(_console_dev, match->name);
err = match->setup(_console_dev, buf);
+   earlycon_info(_console_dev);
if (err < 0)
return err;
if (!early_console_dev.con->write)
@@ -302,6 +308,7 @@ int __init of_setup_earlycon(const struct earlycon_id 
*match,
}
earlycon_init(_console_dev, match->name);
err = match->setup(_console_dev, options);
+   earlycon_info(_console_dev);
if (err < 0)
return err;
if (!early_console_dev.con->write)
-- 
2.28.0.618.gf4bc123cb7-goog



[PATCH 2/2] tty: serial: 8250_mtk: set regshift for mmio32

2020-09-11 Thread Hsin-Yi Wang
To use mmio32, we also need to set regshift.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/tty/serial/8250/8250_mtk.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/serial/8250/8250_mtk.c 
b/drivers/tty/serial/8250/8250_mtk.c
index 7b0dec14c8b80..41f4120abdf29 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -669,6 +669,7 @@ static int __init early_mtk8250_setup(struct 
earlycon_device *device,
return -ENODEV;
 
device->port.iotype = UPIO_MEM32;
+   device->port.regshift = 2;
 
return early_serial8250_setup(device, NULL);
 }
-- 
2.28.0.618.gf4bc123cb7-goog



Re: [PATCH v2 1/2] arm64: dts: mt8173: Set uart to mmio32 iotype

2020-09-10 Thread Hsin-Yi Wang
On Thu, Sep 10, 2020 at 6:25 PM Matthias Brugger  wrote:
>
> Hi,
>
> On 10/09/2020 10:43, Hsin-Yi Wang wrote:
> > Set uart iotype to mmio32 to make earlycon work with stdout-path.
> >
> > Signed-off-by: Hsin-Yi Wang 
> > ---
> >   arch/arm64/boot/dts/mediatek/mt8173.dtsi | 8 
> >   1 file changed, 8 insertions(+)
> >
> > diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
> > b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > index 5e046f9d48ce9..ca6ea71f5f435 100644
> > --- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > +++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > @@ -613,6 +613,8 @@ uart0: serial@11002000 {
> >   interrupts = ;
> >   clocks = < CLK_PERI_UART0_SEL>, < 
> > CLK_PERI_UART0>;
> >   clock-names = "baud", "bus";
> > + reg-io-width = <4>;
>
> Why do we need that, we have
> device->port.iotype = UPIO_MEM32;
> in early_mtk8250_setup(). That should do the job already.
>
>

But if we don't change in dts, we would see
[0.00] earlycon: mtk8250 at MMIO 0x11002000 (options '115200n8')
instead of
[0.00] earlycon: mtk8250 at MMIO32 0x11002000 (options
'115200n8')

Perhaps we should move the pr_info part in earlycon_init() after
match->setup(). Since setup may change iotype. What do you think?


> > + reg-shift = <2>;
>
> Can't we just add
> device->port.regshift = 2;
> to early_mtk8250_setup()? I think that would be a cleaner solution. As the
> serial device is the same for all SoCs, I don't expect any regression here.
>
> CCing Eddie to correct me, if I'm wrong :)
>
> Regards,
> Matthias
>
> >   status = "disabled";
> >   };
> >
> > @@ -623,6 +625,8 @@ uart1: serial@11003000 {
> >   interrupts = ;
> >   clocks = < CLK_PERI_UART1_SEL>, < 
> > CLK_PERI_UART1>;
> >   clock-names = "baud", "bus";
> > + reg-io-width = <4>;
> > + reg-shift = <2>;
> >   status = "disabled";
> >   };
> >
> > @@ -633,6 +637,8 @@ uart2: serial@11004000 {
> >   interrupts = ;
> >   clocks = < CLK_PERI_UART2_SEL>, < 
> > CLK_PERI_UART2>;
> >   clock-names = "baud", "bus";
> > + reg-io-width = <4>;
> > + reg-shift = <2>;
> >   status = "disabled";
> >   };
> >
> > @@ -643,6 +649,8 @@ uart3: serial@11005000 {
> >   interrupts = ;
> >   clocks = < CLK_PERI_UART3_SEL>, < 
> > CLK_PERI_UART3>;
> >   clock-names = "baud", "bus";
> > + reg-io-width = <4>;
> > + reg-shift = <2>;
> >   status = "disabled";
> >   };
> >
> >


Re: [PATCH 1/2] arm64: dts: mt8173: elm: Set uart0 to mmio32 iotype

2020-09-10 Thread Hsin-Yi Wang
On Thu, Sep 10, 2020 at 4:16 PM Enric Balletbo i Serra
 wrote:
>
> Hi Hsin-Yi,
>
> On 10/9/20 9:57, Hsin-Yi Wang wrote:
> > On Thu, Sep 10, 2020 at 3:20 PM Enric Balletbo i Serra
> >  wrote:
> >>
> >> Hi Hsin-Yi,
> >>
> >> On 10/9/20 7:46, Hsin-Yi Wang wrote:
> >>> Set uart0 iotype to mmio32 to make earlycon work with stdout-path.
> >>>
> >>> Signed-off-by: Hsin-Yi Wang 
> >>> ---
> >>>  arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 2 ++
> >>>  1 file changed, 2 insertions(+)
> >>>
> >>> diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
> >>> b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> >>> index a5a12b2599a4a..d54e62f72c65d 100644
> >>> --- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> >>> +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> >>> @@ -1160,6 +1160,8 @@  {
> >>>  };
> >>>
> >>>   {
> >>> + reg-io-width = <4>;
> >>> + reg-shift = <2>;
> >>
> >> I am wondering if these properties are common enough to go to mt8173.dtsi
> >> instead of here.
> >>
> > Since stdout-path is set on elm.dtsi (using uart0), so I add this
> > attribute here.
> >
>
> Why needs to be defined in the same place that stdout-path is set?
>
> My guess is that reg-io-width and reg-shift are SoC specific, as they define 
> how
> the IO access to the register is done. In fact, I think that these properties
> should be added in all the uarts, not only the one that has defined the 
> stdout-path.
>
Okay, I'll apply them to all uart. Thanks.


[PATCH v2 2/2] arm64: dts: mt8183: Set uart to mmio32 iotype

2020-09-10 Thread Hsin-Yi Wang
Set uart iotype to mmio32 to make earlycon work with stdout-path.

Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 102105871db25..0bda97f912789 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -374,6 +374,8 @@ uart0: serial@11002000 {
interrupts = ;
clocks = <>, < CLK_INFRA_UART0>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
@@ -384,6 +386,8 @@ uart1: serial@11003000 {
interrupts = ;
clocks = <>, < CLK_INFRA_UART1>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
@@ -394,6 +398,8 @@ uart2: serial@11004000 {
interrupts = ;
clocks = <>, < CLK_INFRA_UART2>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH v2 1/2] arm64: dts: mt8173: Set uart to mmio32 iotype

2020-09-10 Thread Hsin-Yi Wang
Set uart iotype to mmio32 to make earlycon work with stdout-path.

Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 5e046f9d48ce9..ca6ea71f5f435 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -613,6 +613,8 @@ uart0: serial@11002000 {
interrupts = ;
clocks = < CLK_PERI_UART0_SEL>, < 
CLK_PERI_UART0>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
@@ -623,6 +625,8 @@ uart1: serial@11003000 {
interrupts = ;
clocks = < CLK_PERI_UART1_SEL>, < 
CLK_PERI_UART1>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
@@ -633,6 +637,8 @@ uart2: serial@11004000 {
interrupts = ;
clocks = < CLK_PERI_UART2_SEL>, < 
CLK_PERI_UART2>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
@@ -643,6 +649,8 @@ uart3: serial@11005000 {
interrupts = ;
clocks = < CLK_PERI_UART3_SEL>, < 
CLK_PERI_UART3>;
clock-names = "baud", "bus";
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "disabled";
};
 
-- 
2.28.0.526.ge36021eeef-goog



Re: [PATCH 1/2] arm64: dts: mt8173: elm: Set uart0 to mmio32 iotype

2020-09-10 Thread Hsin-Yi Wang
On Thu, Sep 10, 2020 at 3:20 PM Enric Balletbo i Serra
 wrote:
>
> Hi Hsin-Yi,
>
> On 10/9/20 7:46, Hsin-Yi Wang wrote:
> > Set uart0 iotype to mmio32 to make earlycon work with stdout-path.
> >
> > Signed-off-by: Hsin-Yi Wang 
> > ---
> >  arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
> > b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> > index a5a12b2599a4a..d54e62f72c65d 100644
> > --- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> > +++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
> > @@ -1160,6 +1160,8 @@  {
> >  };
> >
> >   {
> > + reg-io-width = <4>;
> > + reg-shift = <2>;
>
> I am wondering if these properties are common enough to go to mt8173.dtsi
> instead of here.
>
Since stdout-path is set on elm.dtsi (using uart0), so I add this
attribute here.


[PATCH 2/2] arm64: dts: mt8183: kukui: Set uart0 to mmio32 iotype

2020-09-09 Thread Hsin-Yi Wang
Set uart0 iotype to mmio32 to make earlycon work with stdout-path.

Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
index f0a070535b340..f6991bdaac1c6 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
@@ -750,6 +750,8 @@  {
  {
pinctrl-names = "default";
pinctrl-0 = <_pins_default>;
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "okay";
 };
 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH 1/2] arm64: dts: mt8173: elm: Set uart0 to mmio32 iotype

2020-09-09 Thread Hsin-Yi Wang
Set uart0 iotype to mmio32 to make earlycon work with stdout-path.

Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
index a5a12b2599a4a..d54e62f72c65d 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
@@ -1160,6 +1160,8 @@  {
 };
 
  {
+   reg-io-width = <4>;
+   reg-shift = <2>;
status = "okay";
 };
 
-- 
2.28.0.526.ge36021eeef-goog



[PATCH] media: mtk-vcodec: remove allocated dma_parms

2020-09-02 Thread Hsin-Yi Wang
9495b7e92f71 ("driver core: platform: Initialize dma_parms for platform
devices") included dma_parms in platform_device. There's no need to
allocate again.

Fixes: 13483fc2f20f0e2db7ba9c39b095ac7ea46f8de8 ("media: mtk-vcodec: set dma 
max segment size")
Suggested-by: Robin Murphy 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 9 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 9 +
 2 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 3bbd0bac56d69..76ee0cb5a7094 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -242,14 +242,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
-   if (!pdev->dev.dma_parms) {
-   pdev->dev.dma_parms = devm_kzalloc(>dev,
-   sizeof(*pdev->dev.dma_parms),
-   GFP_KERNEL);
-   if (!pdev->dev.dma_parms)
-   return -ENOMEM;
-   }
-   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   dma_set_max_seg_size(>dev, UINT_MAX);
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler,
dev, VPU_RST_DEC);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index ff4a87485d690..c18e58c71d4a4 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -249,14 +249,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
-   if (!pdev->dev.dma_parms) {
-   pdev->dev.dma_parms = devm_kzalloc(>dev,
-   sizeof(*pdev->dev.dma_parms),
-   GFP_KERNEL);
-   if (!pdev->dev.dma_parms)
-   return -ENOMEM;
-   }
-   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   dma_set_max_seg_size(>dev, UINT_MAX);
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_enc_reset_handler,
dev, VPU_RST_ENC);
-- 
2.28.0.402.g5ffc5be6b7-goog



Re: [PATCH] media: mtk-vcodec: set dma max segment size

2020-09-02 Thread Hsin-Yi Wang
On Wed, Sep 2, 2020 at 10:25 PM Robin Murphy  wrote:
>
> On 2020-08-21 05:14, Hsin-Yi Wang wrote:
> > Set dma max segment size for encoder and decoder driver.
> >
> > Fix following warning with CONFIG_DMA_API_DEBUG_SG=y
> >
> > [   75.147825] [ cut here ]
> > [   75.147844] mtk-vcodec-enc 19002000.vcodec: DMA-API: mapping sg segment 
> > longer than device claims to support [len=983040] [max=65536]
> > [   75.147876] WARNING: CPU: 2 PID: 4069 at kernel/dma/debug.c:1302 
> > debug_dma_map_sg+0x1a8/0x2c4
> > ...
> > [   75.148139] Call trace:
> > [   75.148149]  debug_dma_map_sg+0x1a8/0x2c4
> > [   75.148165]  vb2_dc_get_userptr+0x228/0x364 [videobuf2_dma_contig]
> > [   75.148178]  __buf_prepare+0x3ac/0x8c0 [videobuf2_common]
> > [   75.148188]  vb2_core_qbuf+0xa4/0x58c [videobuf2_common]
> > [   75.148199]  vb2_qbuf+0x88/0xe4 [videobuf2_v4l2]
> > [   75.148211]  v4l2_m2m_qbuf+0x80/0xf8 [v4l2_mem2mem]
> > [   75.148221]  vidioc_venc_qbuf+0x3c/0x70 [mtk_vcodec_enc]
> > [   75.148234]  v4l_qbuf+0x48/0x58
> > [   75.148242]  __video_do_ioctl+0x200/0x37c
> > [   75.148250]  video_usercopy+0x360/0x834
> > [   75.148259]  video_ioctl2+0x38/0x48
> > [   75.148267]  v4l2_ioctl+0x6c/0x80
> > [   75.148276]  do_video_ioctl+0xefc/0x4b70
> > [   75.148284]  v4l2_compat_ioctl32+0x5c/0xcc
> > [   75.148294]  __arm64_compat_sys_ioctl+0xf4/0x240
> > [   75.148304]  el0_svc_common+0xac/0x198
> > [   75.148312]  el0_svc_compat_handler+0x2c/0x40
> > [   75.148321]  el0_svc_compat+0x8/0x18
> > [   75.148328] irq event stamp: 0
> > [   75.148337] hardirqs last  enabled at (0): [<>]  
> >  (null)
> > [   75.148347] hardirqs last disabled at (0): [] 
> > copy_process+0x380/0x115c
> > [   75.148356] softirqs last  enabled at (0): [] 
> > copy_process+0x398/0x115c
> > [   75.148364] softirqs last disabled at (0): [<>]  
> >  (null)
> > [   75.148372] ---[ end trace 588bf529451e3531 ]---
> >
> > Reported-by: Anand K Mistry 
> > Signed-off-by: Hsin-Yi Wang 
> > ---
> >   drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 8 
> >   drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 8 
> >   2 files changed, 16 insertions(+)
> >
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
> > b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
> > index 97a1b6664c20..3bbd0bac56d6 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
> > @@ -242,6 +242,14 @@ static int mtk_vcodec_probe(struct platform_device 
> > *pdev)
> >   mtk_v4l2_err("[VPU] vpu device in not ready");
> >   return -EPROBE_DEFER;
> >   }
> > + if (!pdev->dev.dma_parms) {
> > + pdev->dev.dma_parms = devm_kzalloc(>dev,
> > + sizeof(*pdev->dev.dma_parms),
> > + GFP_KERNEL);
> > + if (!pdev->dev.dma_parms)
> > + return -ENOMEM;
> > + }
>
> Since 9495b7e92f71, dma_parms is included in the platform_device itself
> and always set, so you can drop these allocation paths.
>
> > + dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
>
> The segment size is simply a size, not a bitmask, so UINT_MAX would be
> more semantically appropriate.
>
> Robin.
>

Thanks. since this patch is already in media tree:
https://git.linuxtv.org/media_tree.git/commit/?id=13483fc2f20f0e2db7ba9c39b095ac7ea46f8de8,
I'll send a patch to modify this.


[PATCH] media: mtk-vcodec: set dma max segment size

2020-08-20 Thread Hsin-Yi Wang
Set dma max segment size for encoder and decoder driver.

Fix following warning with CONFIG_DMA_API_DEBUG_SG=y

[   75.147825] [ cut here ]
[   75.147844] mtk-vcodec-enc 19002000.vcodec: DMA-API: mapping sg segment 
longer than device claims to support [len=983040] [max=65536]
[   75.147876] WARNING: CPU: 2 PID: 4069 at kernel/dma/debug.c:1302 
debug_dma_map_sg+0x1a8/0x2c4
...
[   75.148139] Call trace:
[   75.148149]  debug_dma_map_sg+0x1a8/0x2c4
[   75.148165]  vb2_dc_get_userptr+0x228/0x364 [videobuf2_dma_contig]
[   75.148178]  __buf_prepare+0x3ac/0x8c0 [videobuf2_common]
[   75.148188]  vb2_core_qbuf+0xa4/0x58c [videobuf2_common]
[   75.148199]  vb2_qbuf+0x88/0xe4 [videobuf2_v4l2]
[   75.148211]  v4l2_m2m_qbuf+0x80/0xf8 [v4l2_mem2mem]
[   75.148221]  vidioc_venc_qbuf+0x3c/0x70 [mtk_vcodec_enc]
[   75.148234]  v4l_qbuf+0x48/0x58
[   75.148242]  __video_do_ioctl+0x200/0x37c
[   75.148250]  video_usercopy+0x360/0x834
[   75.148259]  video_ioctl2+0x38/0x48
[   75.148267]  v4l2_ioctl+0x6c/0x80
[   75.148276]  do_video_ioctl+0xefc/0x4b70
[   75.148284]  v4l2_compat_ioctl32+0x5c/0xcc
[   75.148294]  __arm64_compat_sys_ioctl+0xf4/0x240
[   75.148304]  el0_svc_common+0xac/0x198
[   75.148312]  el0_svc_compat_handler+0x2c/0x40
[   75.148321]  el0_svc_compat+0x8/0x18
[   75.148328] irq event stamp: 0
[   75.148337] hardirqs last  enabled at (0): [<>]   
(null)
[   75.148347] hardirqs last disabled at (0): [] 
copy_process+0x380/0x115c
[   75.148356] softirqs last  enabled at (0): [] 
copy_process+0x398/0x115c
[   75.148364] softirqs last disabled at (0): [<>]   
(null)
[   75.148372] ---[ end trace 588bf529451e3531 ]---

Reported-by: Anand K Mistry 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 8 
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 8 
 2 files changed, 16 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 97a1b6664c20..3bbd0bac56d6 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -242,6 +242,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
+   if (!pdev->dev.dma_parms) {
+   pdev->dev.dma_parms = devm_kzalloc(>dev,
+   sizeof(*pdev->dev.dma_parms),
+   GFP_KERNEL);
+   if (!pdev->dev.dma_parms)
+   return -ENOMEM;
+   }
+   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler,
dev, VPU_RST_DEC);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index 4d31f1ed113f..ff4a87485d69 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -249,6 +249,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
+   if (!pdev->dev.dma_parms) {
+   pdev->dev.dma_parms = devm_kzalloc(>dev,
+   sizeof(*pdev->dev.dma_parms),
+   GFP_KERNEL);
+   if (!pdev->dev.dma_parms)
+   return -ENOMEM;
+   }
+   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_enc_reset_handler,
dev, VPU_RST_ENC);
-- 
2.28.0.297.g1956fa8f8d-goog



[PATCH] regulator: da9211: add cache_type

2020-08-12 Thread Hsin-Yi Wang
Add regmap_cache to reduce wakeups events of interrupt if regulator is
accessed frequently. This results in saving more power.

Suggested-by: Daniel Kurtz 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/regulator/da9211-regulator.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/regulator/da9211-regulator.c 
b/drivers/regulator/da9211-regulator.c
index 297b3aa7c753..cffcefd0538d 100644
--- a/drivers/regulator/da9211-regulator.c
+++ b/drivers/regulator/da9211-regulator.c
@@ -51,10 +51,24 @@ static const struct regmap_range_cfg da9211_regmap_range[] 
= {
},
 };
 
+static bool da9211_volatile_reg(struct device *dev, unsigned int reg)
+{
+   switch (reg) {
+   case DA9211_REG_STATUS_A:
+   case DA9211_REG_STATUS_B:
+   case DA9211_REG_EVENT_A:
+   case DA9211_REG_EVENT_B:
+   return true;
+   }
+   return false;
+}
+
 static const struct regmap_config da9211_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 5 * 128,
+   .volatile_reg = da9211_volatile_reg,
+   .cache_type = REGCACHE_RBTREE,
.ranges = da9211_regmap_range,
.num_ranges = ARRAY_SIZE(da9211_regmap_range),
 };
-- 
2.28.0.236.gb10cc79966-goog



[PATCH] arm64: dts: mt8173: elm: Fix nor_flash node property

2020-07-27 Thread Hsin-Yi Wang
bus-width and non-removable is not used by the driver.
max-frequency should be spi-max-frequency for flash node.

Fixes: 689b937bedde ("arm64: dts: mediatek: add mt8173 elm and hana board")
Reported-by: Nicolas Boichat 
Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
index a5a12b2599a4..01522dd10603 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi
@@ -431,12 +431,11 @@ _flash {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_gpio1_pins>;
-   bus-width = <8>;
-   max-frequency = <5000>;
-   non-removable;
+
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
+   spi-max-frequency = <5000>;
};
 };
 
-- 
2.28.0.rc0.142.g3c755180ce-goog



Re: [PATCH] arm64: dts: mt8173: Re-measure capacity-dmips-mhz

2020-07-08 Thread Hsin-Yi Wang
On Thu, Jul 9, 2020 at 1:01 AM Matthias Brugger  wrote:
>
>
>
> On 06/07/2020 10:37, Hsin-Yi Wang wrote:
> > Re measure capacity-dmips-mhz on elm and hana:
> >
> > cpu 1:  9502 DMIPS @ 1703 Mhz
> > cpu 3: 16250 DMIPS @ 2106 Mhz
> >
> > ==> 740 : 1024
>
> I have some trouble to match the commit message to the actual patch. Commit
> message talks about cpu 1 but patch changes cpu0. Where are the values of the
> other CPUs?

Small cpu on 8173 is cpu0 & cpu1, while big cpu is cpu2 & cpu3.
Small cpu: 9502 DMIPS @ 1703 Mhz
Big cpu:   16250 DMIPS @ 2106 Mhz

9502/1703 : 16250/2106 = 740 : 1024 (scale big cpu to 1024), and this patch
changes the small cpu value to 740.



>
> Regards,
> Matthias
>
> >
> > Signed-off-by: Hsin-Yi Wang 
> > ---
> >   arch/arm64/boot/dts/mediatek/mt8173.dtsi | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
> > b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > index 70b1ffcab7f0..5e046f9d48ce 100644
> > --- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > +++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
> > @@ -167,7 +167,7 @@ cpu0: cpu@0 {
> >< CLK_APMIXED_MAINPLL>;
> >   clock-names = "cpu", "intermediate";
> >   operating-points-v2 = <_opp>;
> > - capacity-dmips-mhz = <526>;
> > + capacity-dmips-mhz = <740>;
> >   };
> >
> >   cpu1: cpu@1 {
> > @@ -182,7 +182,7 @@ cpu1: cpu@1 {
> >< CLK_APMIXED_MAINPLL>;
> >   clock-names = "cpu", "intermediate";
> >   operating-points-v2 = <_opp>;
> > - capacity-dmips-mhz = <526>;
> > + capacity-dmips-mhz = <740>;
> >   };
> >
> >   cpu2: cpu@100 {
> >


[PATCH] arm64: dts: mt8173: Re-measure capacity-dmips-mhz

2020-07-06 Thread Hsin-Yi Wang
Re measure capacity-dmips-mhz on elm and hana:

cpu 1:  9502 DMIPS @ 1703 Mhz
cpu 3: 16250 DMIPS @ 2106 Mhz

==> 740 : 1024

Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 70b1ffcab7f0..5e046f9d48ce 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -167,7 +167,7 @@ cpu0: cpu@0 {
 < CLK_APMIXED_MAINPLL>;
clock-names = "cpu", "intermediate";
operating-points-v2 = <_opp>;
-   capacity-dmips-mhz = <526>;
+   capacity-dmips-mhz = <740>;
};
 
cpu1: cpu@1 {
@@ -182,7 +182,7 @@ cpu1: cpu@1 {
 < CLK_APMIXED_MAINPLL>;
clock-names = "cpu", "intermediate";
operating-points-v2 = <_opp>;
-   capacity-dmips-mhz = <526>;
+   capacity-dmips-mhz = <740>;
};
 
cpu2: cpu@100 {
-- 
2.27.0.212.ge8ba1cc988-goog



Re: [PATCH v2 7/7] arm64: dts: mt8183: Add krane-sku176 board

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> Also known as the Lenovo IdeaPad Duet Chromebook.
>
> There are different krane boards with shared resources, hence a
> mt8183-kukui-krane.dtsi was created for easily introduce future new
> boards. The same happens with the baseboard codenamed kukui where
> different variants, apart from kukui variant can take advantage of the
> shared resources.
>
> Signed-off-by: Ben Ho 
> [originally created by Ben Ho but adapted and ported to mainline]
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2:
> - Move adding #phy-cells out of this patch. (Matthias Brugger)
>
>  arch/arm64/boot/dts/mediatek/Makefile |   1 +
>  .../mediatek/mt8183-kukui-krane-sku176.dts|  18 +
>  .../boot/dts/mediatek/mt8183-kukui-krane.dtsi | 343 
>  .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 788 ++
>  4 files changed, 1150 insertions(+)
>  create mode 100644 arch/arm64/boot/dts/mediatek/mt8183-kukui-krane-sku176.dts
>  create mode 100644 arch/arm64/boot/dts/mediatek/mt8183-kukui-krane.dtsi
>  create mode 100644 arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi
>
> diff --git a/arch/arm64/boot/dts/mediatek/Makefile 
> b/arch/arm64/boot/dts/mediatek/Makefile
> index 848218f55bc1d..708fc60fa589a 100644
> --- a/arch/arm64/boot/dts/mediatek/Makefile
> +++ b/arch/arm64/boot/dts/mediatek/Makefile
> @@ -12,4 +12,5 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += mt8173-elm-hana.dtb
>  dtb-$(CONFIG_ARCH_MEDIATEK) += mt8173-elm-hana-rev7.dtb
>  dtb-$(CONFIG_ARCH_MEDIATEK) += mt8173-evb.dtb
>  dtb-$(CONFIG_ARCH_MEDIATEK) += mt8183-evb.dtb
> +dtb-$(CONFIG_ARCH_MEDIATEK) += mt8183-kukui-krane-sku176.dtb
>  dtb-$(CONFIG_ARCH_MEDIATEK) += mt8516-pumpkin.dtb
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane-sku176.dts 
> b/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane-sku176.dts
> new file mode 100644
> index 0..47113e275cb52
> --- /dev/null
> +++ b/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane-sku176.dts
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +/*
> + * Copyright 2019 Google LLC
> + *
> + * Device-tree for Krane sku176.
> + *
> + * SKU is a 8-bit value (0xb0 == 176):
> + *  - Bits 7..4: Panel ID: 0xb (BOE)
> + *  - Bits 3..0: SKU ID:   0x0 (default)
> + */
> +
> +/dts-v1/;
> +#include "mt8183-kukui-krane.dtsi"
> +
> +/ {
> +   model = "MediaTek krane sku176 board";
> +   compatible = "google,krane-sku176", "google,krane", "mediatek,mt8183";
> +};
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane.dtsi
> new file mode 100644
> index 0..fbc471ccf805f
> --- /dev/null
> +++ b/arch/arm64/boot/dts/mediatek/mt8183-kukui-krane.dtsi
> @@ -0,0 +1,343 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +/*
> + * Copyright 2019 Google LLC
> + */
> +
> +#include "mt8183-kukui.dtsi"
> +
> +/ {
> +   ppvarn_lcd: ppvarn-lcd {
> +   compatible = "regulator-fixed";
> +   regulator-name = "ppvarn_lcd";
> +   pinctrl-names = "default";
> +   pinctrl-0 = <_lcd_en>;
> +
> +   enable-active-high;
> +
> +   gpio = < 66 GPIO_ACTIVE_HIGH>;
> +   };
> +
> +   ppvarp_lcd: ppvarp-lcd {
> +   compatible = "regulator-fixed";
> +   regulator-name = "ppvarp_lcd";
> +   pinctrl-names = "default";
> +   pinctrl-0 = <_lcd_en>;
> +
> +   enable-active-high;
> +
> +   gpio = < 166 GPIO_ACTIVE_HIGH>;
> +   };
> +
> +   pp1800_lcd: pp1800-lcd {
> +   compatible = "regulator-fixed";
> +   regulator-name = "pp1800_lcd";
> +   pinctrl-names = "default";
> +   pinctrl-0 = <_lcd_en>;
> +
> +   enable-active-high;
> +
> +   gpio = < 36 GPIO_ACTIVE_HIGH>;
> +   };
> +};
> +
> + {
> +   firmware-name = "nvm_00440302_i2s_eu.bin";
> +};
> +
> + {
> +   status = "okay";
> +
> +   touchscreen4: touchscreen@5d {
> +   compatible = "hid-over-i2c";
> +   reg = <0x5d>;
> +   pinctrl-names = "default";
> +   pinctrl-0 = <_touch>;
> +
> +   interrupt-parent = <>;
> +   interrupts = <155 IRQ_TYPE_EDGE

Re: [PATCH v2 6/7] arm64: dts: mt8183: Add USB3.0 support

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> Add the USB3.0 phyter and controller for the MediaTek's MT8183 SoC.
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2:
> - Move adding #phy-cells to this patch. (Matthias Brugger)
>
>  arch/arm64/boot/dts/mediatek/mt8183.dtsi | 58 
>  1 file changed, 58 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> index 6c00ffa275202..102105871db25 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> @@ -9,6 +9,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "mt8183-pinfunc.h"
>
>  / {
> @@ -648,6 +649,36 @@ i2c8: i2c@1101b000 {
> status = "disabled";
> };
>
> +   ssusb: usb@11201000 {
> +   compatible ="mediatek,mt8183-mtu3", "mediatek,mtu3";
> +   reg = <0 0x11201000 0 0x2e00>,
> + <0 0x11203e00 0 0x0100>;
> +   reg-names = "mac", "ippc";
> +   interrupts = ;
> +   phys = < PHY_TYPE_USB2>,
> +  < PHY_TYPE_USB3>;
> +   clocks = < CLK_INFRA_UNIPRO_SCK>,
> +< CLK_INFRA_USB>;
> +   clock-names = "sys_ck", "ref_ck";
> +   mediatek,syscon-wakeup = < 0x400 0>;
> +   #address-cells = <2>;
> +   #size-cells = <2>;
> +   ranges;
> +   status = "disabled";
> +
> +   usb_host: xhci@1120 {
> +   compatible = "mediatek,mt8183-xhci",
> +"mediatek,mtk-xhci";
> +   reg = <0 0x1120 0 0x1000>;
> +   reg-names = "mac";
> +   interrupts = ;
> +   clocks = < CLK_INFRA_UNIPRO_SCK>,
> +< CLK_INFRA_USB>;
> +   clock-names = "sys_ck", "ref_ck";
> +   status = "disabled";
> +   };
> +   };
> +
> audiosys: syscon@1122 {
> compatible = "mediatek,mt8183-audiosys", "syscon";
> reg = <0 0x1122 0 0x1000>;
> @@ -684,6 +715,33 @@ efuse: efuse@11f1 {
> reg = <0 0x11f1 0 0x1000>;
> };
>
> +   u3phy: usb-phy@11f4 {
> +   compatible = "mediatek,mt8183-tphy",
> +"mediatek,generic-tphy-v2";
> +   #address-cells = <1>;
> +   #phy-cells = <1>;
> +   #size-cells = <1>;
> +   ranges = <0 0 0x11f4 0x1000>;
> +   status = "okay";
> +
> +   u2port0: usb-phy@0 {
> +   reg = <0x0 0x700>;
> +   clocks = <>;
> +   clock-names = "ref";
> +   #phy-cells = <1>;
> +   mediatek,discth = <15>;
> +   status = "okay";
> +   };
> +
> +   u3port0: usb-phy@0700 {
> +   reg = <0x0700 0x900>;
> +   clocks = <>;
> +   clock-names = "ref";
> +   #phy-cells = <1>;
> +   status = "okay";
> +   };
> +   };
> +
> mfgcfg: syscon@1300 {
> compatible = "mediatek,mt8183-mfgcfg", "syscon";
> reg = <0 0x1300 0 0x1000>;
> --
> 2.27.0
>


Re: [PATCH v2 3/7] arm64: dts: mt8183: Add MediaTek's peripheral configuration controller

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> The MediaTek's peripheral configuration controller is present on the
> MT8183 SoC. Add the node for that controller.
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2: None
>
>  arch/arm64/boot/dts/mediatek/mt8183.dtsi | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> index 1e03c849dc5d6..00137ec61164d 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> @@ -285,6 +285,12 @@ infracfg: syscon@10001000 {
> #reset-cells = <1>;
> };
>
> +   pericfg: syscon@10003000 {
> +   compatible = "mediatek,mt8183-pericfg", "syscon";
> +   reg = <0 0x10003000 0 0x1000>;
> +   #clock-cells = <1>;
> +   };
> +
> pio: pinctrl@10005000 {
> compatible = "mediatek,mt8183-pinctrl";
> reg = <0 0x10005000 0 0x1000>,
> --
> 2.27.0
>


Re: [PATCH v2 5/7] arm64: dts: mt8183-evb: Fix unit name warnings

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> Remove the unit address from the DT nodes that doesn't have a reg
> property. This fixes the following unit name warnings:
>
> Warning (unit_address_vs_reg): /soc/pinctrl@10005000/mmc0@0: node has a 
> unit name, but no reg or ranges property
> Warning (unit_address_vs_reg): /soc/pinctrl@10005000/mmc1@0: node has a 
> unit name, but no reg or ranges property
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2: None
>
>  arch/arm64/boot/dts/mediatek/mt8183-evb.dts | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183-evb.dts 
> b/arch/arm64/boot/dts/mediatek/mt8183-evb.dts
> index afd6ddbcbdf2c..ae405bd8f06b0 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183-evb.dts
> +++ b/arch/arm64/boot/dts/mediatek/mt8183-evb.dts
> @@ -205,7 +205,7 @@ pins_rst {
> };
> };
>
> -   mmc0_pins_uhs: mmc0@0{
> +   mmc0_pins_uhs: mmc0 {
> pins_cmd_dat {
> pinmux = ,
>  ,
> @@ -264,7 +264,7 @@ pins_pmu {
> };
> };
>
> -   mmc1_pins_uhs: mmc1@0{
> +   mmc1_pins_uhs: mmc1 {
> pins_cmd_dat {
> pinmux = ,
>,
> --
> 2.27.0
>


Re: [PATCH v2 4/7] arm64: dts: mt8183: Fix unit name warnings

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> Remove the unit address from the DT nodes that doesn't have a reg
> property. This fixes the following unit name warnings:
>
>   Warning (unit_address_vs_reg): /cpus/idle-states/cluster-sleep@0: node has 
> a unit name, but no reg or ranges property
>   Warning (unit_address_vs_reg): /cpus/idle-states/cluster-sleep@1: node has 
> a unit name, but no reg or ranges property
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2:
> - Replace cluster-sleepX for cluster-sleep-x (Matthias Brugger)
>
>  arch/arm64/boot/dts/mediatek/mt8183.dtsi | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> index 00137ec61164d..6c00ffa275202 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
> @@ -168,7 +168,7 @@ CPU_SLEEP: cpu-sleep {
> min-residency-us = <800>;
> };
>
> -   CLUSTER_SLEEP0: cluster-sleep@0 {
> +   CLUSTER_SLEEP0: cluster-sleep-0 {
> compatible = "arm,idle-state";
> local-timer-stop;
> arm,psci-suspend-param = <0x01010001>;
> @@ -176,7 +176,7 @@ CLUSTER_SLEEP0: cluster-sleep@0 {
> exit-latency-us = <400>;
> min-residency-us = <1000>;
> };
> -   CLUSTER_SLEEP1: cluster-sleep@1 {
> +   CLUSTER_SLEEP1: cluster-sleep-1 {
> compatible = "arm,idle-state";
> local-timer-stop;
> arm,psci-suspend-param = <0x01010001>;
> --
> 2.27.0
>


Re: [PATCH v2 2/7] arm64: dts: mt6358: Add the compatible for the regulators

2020-07-01 Thread Hsin-Yi Wang
On Thu, Jun 25, 2020 at 6:18 PM Enric Balletbo i Serra
 wrote:
>
> The regulators are expected to be instantiated with matching the
> device-tree compatible, so add the proper compatible name under the
> regulators node.
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 
> ---
>
> Changes in v2: None
>
>  arch/arm64/boot/dts/mediatek/mt6358.dtsi | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/mediatek/mt6358.dtsi 
> b/arch/arm64/boot/dts/mediatek/mt6358.dtsi
> index 9361ada0c497e..fa159b20379e4 100644
> --- a/arch/arm64/boot/dts/mediatek/mt6358.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt6358.dtsi
> @@ -16,6 +16,8 @@ mt6358codec: mt6358codec {
> };
>
> mt6358regulator: mt6358regulator {
> +   compatible = "mediatek,mt6358-regulator";
> +
> mt6358_vdram1_reg: buck_vdram1 {
> regulator-name = "vdram1";
> regulator-min-microvolt = <50>;
> --
> 2.27.0
>


[PATCH v4] drm/mediatek: check plane visibility in atomic_update

2020-06-22 Thread Hsin-Yi Wang
Disable the plane if it's not visible. Otherwise mtk_ovl_layer_config()
would proceed with invalid plane and we may see vblank timeout.

Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Chun-Kuang Hu 
Reviewed-by: Tomasz Figa 
---
v4: fix commit message
v3: Address comment
v2: Add fixes tag
---
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 25 ++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c 
b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
index c2bd683a87c8..92141a19681b 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
@@ -164,6 +164,16 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
   true, true);
 }
 
+static void mtk_plane_atomic_disable(struct drm_plane *plane,
+struct drm_plane_state *old_state)
+{
+   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
+
+   state->pending.enable = false;
+   wmb(); /* Make sure the above parameter is set before update */
+   state->pending.dirty = true;
+}
+
 static void mtk_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
 {
@@ -178,6 +188,11 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
if (!crtc || WARN_ON(!fb))
return;
 
+   if (!plane->state->visible) {
+   mtk_plane_atomic_disable(plane, old_state);
+   return;
+   }
+
gem = fb->obj[0];
mtk_gem = to_mtk_gem_obj(gem);
addr = mtk_gem->dma_addr;
@@ -200,16 +215,6 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
state->pending.dirty = true;
 }
 
-static void mtk_plane_atomic_disable(struct drm_plane *plane,
-struct drm_plane_state *old_state)
-{
-   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
-
-   state->pending.enable = false;
-   wmb(); /* Make sure the above parameter is set before update */
-   state->pending.dirty = true;
-}
-
 static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
.prepare_fb = drm_gem_fb_prepare_fb,
.atomic_check = mtk_plane_atomic_check,
-- 
2.27.0.111.gc72c7da667-goog



Re: [PATCH v2] drm/mediatek: check plane visibility in atomic_update

2020-06-22 Thread Hsin-Yi Wang
On Mon, Jun 22, 2020 at 11:20 PM Tomasz Figa  wrote:
>
> Hi Hsin-Yi,
>
> On Mon, Jun 22, 2020 at 11:01:09PM +0800, Hsin-Yi Wang wrote:
> > Disable the plane if it's not visible. Otherwise mtk_ovl_layer_config()
> > would proceed with invalid plane and we may see vblank timeout.
> >
> > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC 
> > MT8173.")
> > Signed-off-by: Hsin-Yi Wang 
> > Reviewed-by: Chun-Kuang Hu 
> > ---
> > v2: Add fixes tag
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_plane.c | 23 +--
> >  1 file changed, 13 insertions(+), 10 deletions(-)
> >
>
> Thank you for the patch. Please see my comments inline.
>
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c 
> > b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
> > index c2bd683a87c8..74dc71c7f3b6 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
> > @@ -164,6 +164,16 @@ static int mtk_plane_atomic_check(struct drm_plane 
> > *plane,
> >  true, true);
> >  }
> >
> > +static void mtk_plane_atomic_disable(struct drm_plane *plane,
> > +  struct drm_plane_state *old_state)
> > +{
> > + struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
> > +
> > + state->pending.enable = false;
> > + wmb(); /* Make sure the above parameter is set before update */
> > + state->pending.dirty = true;
> > +}
> > +
> >  static void mtk_plane_atomic_update(struct drm_plane *plane,
> >   struct drm_plane_state *old_state)
> >  {
> > @@ -178,6 +188,9 @@ static void mtk_plane_atomic_update(struct drm_plane 
> > *plane,
> >   if (!crtc || WARN_ON(!fb))
> >   return;
> >
> > + if (!plane->state->visible)
> > + return mtk_plane_atomic_disable(plane, old_state);
>
> nit: Both this function and mtk_plane_atomic_disable() have the void return
> type. Perhaps we should rather move the return, without a value, to a
> separate statement?
Updated in v3, thanks.

>
> Best regards,
> Tomasz


[PATCH v3] drm/mediatek: check plane visibility in atomic_update

2020-06-22 Thread Hsin-Yi Wang
Disable the plane if it's not visible. Otherwise mtk_ovl_layer_config()
would proceed with invalid plane and we may see vblank timeout.

Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Chun-Kuang Hu 
Change-Id: Id5341d60ddfffc88a38d9db0caa089b2d6a1d29c
---
v3: Address comment
v2: Add fixes tag
---
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 25 ++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c 
b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
index c2bd683a87c8..92141a19681b 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
@@ -164,6 +164,16 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
   true, true);
 }
 
+static void mtk_plane_atomic_disable(struct drm_plane *plane,
+struct drm_plane_state *old_state)
+{
+   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
+
+   state->pending.enable = false;
+   wmb(); /* Make sure the above parameter is set before update */
+   state->pending.dirty = true;
+}
+
 static void mtk_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
 {
@@ -178,6 +188,11 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
if (!crtc || WARN_ON(!fb))
return;
 
+   if (!plane->state->visible) {
+   mtk_plane_atomic_disable(plane, old_state);
+   return;
+   }
+
gem = fb->obj[0];
mtk_gem = to_mtk_gem_obj(gem);
addr = mtk_gem->dma_addr;
@@ -200,16 +215,6 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
state->pending.dirty = true;
 }
 
-static void mtk_plane_atomic_disable(struct drm_plane *plane,
-struct drm_plane_state *old_state)
-{
-   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
-
-   state->pending.enable = false;
-   wmb(); /* Make sure the above parameter is set before update */
-   state->pending.dirty = true;
-}
-
 static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
.prepare_fb = drm_gem_fb_prepare_fb,
.atomic_check = mtk_plane_atomic_check,
-- 
2.27.0.111.gc72c7da667-goog



[PATCH v2] drm/mediatek: check plane visibility in atomic_update

2020-06-22 Thread Hsin-Yi Wang
Disable the plane if it's not visible. Otherwise mtk_ovl_layer_config()
would proceed with invalid plane and we may see vblank timeout.

Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Chun-Kuang Hu 
---
v2: Add fixes tag
---
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c 
b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
index c2bd683a87c8..74dc71c7f3b6 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
@@ -164,6 +164,16 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
   true, true);
 }
 
+static void mtk_plane_atomic_disable(struct drm_plane *plane,
+struct drm_plane_state *old_state)
+{
+   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
+
+   state->pending.enable = false;
+   wmb(); /* Make sure the above parameter is set before update */
+   state->pending.dirty = true;
+}
+
 static void mtk_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
 {
@@ -178,6 +188,9 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
if (!crtc || WARN_ON(!fb))
return;
 
+   if (!plane->state->visible)
+   return mtk_plane_atomic_disable(plane, old_state);
+
gem = fb->obj[0];
mtk_gem = to_mtk_gem_obj(gem);
addr = mtk_gem->dma_addr;
@@ -200,16 +213,6 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
state->pending.dirty = true;
 }
 
-static void mtk_plane_atomic_disable(struct drm_plane *plane,
-struct drm_plane_state *old_state)
-{
-   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
-
-   state->pending.enable = false;
-   wmb(); /* Make sure the above parameter is set before update */
-   state->pending.dirty = true;
-}
-
 static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
.prepare_fb = drm_gem_fb_prepare_fb,
.atomic_check = mtk_plane_atomic_check,
-- 
2.27.0.111.gc72c7da667-goog



[PATCH] drm/mediatek: check plane visibility in atomic_update

2020-06-21 Thread Hsin-Yi Wang
Disable the plane if it's not visible. Otherwise mtk_ovl_layer_config()
would proceed with invalid plane and we may see vblank timeout.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/gpu/drm/mediatek/mtk_drm_plane.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c 
b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
index c2bd683a87c8..74dc71c7f3b6 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
@@ -164,6 +164,16 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
   true, true);
 }
 
+static void mtk_plane_atomic_disable(struct drm_plane *plane,
+struct drm_plane_state *old_state)
+{
+   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
+
+   state->pending.enable = false;
+   wmb(); /* Make sure the above parameter is set before update */
+   state->pending.dirty = true;
+}
+
 static void mtk_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
 {
@@ -178,6 +188,9 @@ static void mtk_plane_atomic_update(struct drm_plane *plane,
if (!crtc || WARN_ON(!fb))
return;
 
+   if (!plane->state->visible)
+   return mtk_plane_atomic_disable(plane, old_state);
+
gem = fb->obj[0];
mtk_gem = to_mtk_gem_obj(gem);
addr = mtk_gem->dma_addr;
@@ -200,16 +213,6 @@ static void mtk_plane_atomic_update(struct drm_plane 
*plane,
state->pending.dirty = true;
 }
 
-static void mtk_plane_atomic_disable(struct drm_plane *plane,
-struct drm_plane_state *old_state)
-{
-   struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
-
-   state->pending.enable = false;
-   wmb(); /* Make sure the above parameter is set before update */
-   state->pending.dirty = true;
-}
-
 static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
.prepare_fb = drm_gem_fb_prepare_fb,
.atomic_check = mtk_plane_atomic_check,
-- 
2.27.0.111.gc72c7da667-goog



Re: [PATCH v11 2/2] drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP bridge driver

2020-05-31 Thread Hsin-Yi Wang
On Fri, May 15, 2020 at 2:53 PM Xin Ji  wrote:

> +
> +static int anx7625_bridge_attach(struct drm_bridge *bridge)

Latest drm_bridge api:

int (*attach)(struct drm_bridge *bridge,
 enum drm_bridge_attach_flags flags);

https://elixir.bootlin.com/linux/v5.7-rc7/source/include/drm/drm_bridge.h#L70

> +{
> +   struct anx7625_data *ctx = bridge_to_anx7625(bridge);
> +   int err;


Re: [PATCH v2 1/4] soc: mediatek: Enable mmsys driver by default if Mediatek arch is selected

2020-05-12 Thread Hsin-Yi Wang
On Thu, Apr 2, 2020 at 4:17 AM Enric Balletbo i Serra
 wrote:
>
> The mmsys driver supports only MT8173 device for now, but like other system
> controllers is an important piece for other Mediatek devices. Actually
> it depends on the mt8173 clock specific driver but that dependency is
> not real as it can build without the clock driver. Instead of depends on
> a specific model, make the driver depends on the generic ARCH_MEDIATEK and
> enable by default so other Mediatek devices can start using it without
> flood the Kconfig.
>
> Signed-off-by: Enric Balletbo i Serra 
Tested-by: Hsin-Yi Wang 


[PATCH] arm64: dts: mt8173: fix vcodec-enc clock

2020-05-04 Thread Hsin-Yi Wang
Fix the assigned-clock-parents to higher frequency clock to avoid h264
encode timeout:

[  134.763465] mtk_vpu 1002.vpu: vpu ipi 4 ack time out !
[  134.769008] [MTK_VCODEC][ERROR][18]: vpu_enc_send_msg() vpu_ipi_send msg_id 
c002 len 32 fail -5
[  134.07] [MTK_VCODEC][ERROR][18]: vpu_enc_encode() AP_IPIMSG_ENC_ENCODE 0 
fail

venc_sel is the clock used by h264 encoder, and venclt_sel is the clock
used by vp8 encoder. Assign venc_sel to vcodecpll_ck and venclt_sel to
vcodecpll_370p5.

vcodecpll 148200
   vcodecpll_ck49400
  venc_sel 49400
...
   vcodecpll_370p5 37050
  venclt_sel   37050

Fixes: fbbad0287cec ("arm64: dts: Using standard CCF interface to set vcodec 
clk")
Signed-off-by: Hsin-Yi Wang 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index a212bf124e81..d0e9a2aada2e 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -1422,8 +1422,8 @@ vcodec_enc: vcodec@18002000 {
  "venc_lt_sel";
assigned-clocks = < CLK_TOP_VENC_SEL>,
  < CLK_TOP_VENC_LT_SEL>;
-   assigned-clock-parents = < CLK_TOP_VENCPLL_D2>,
-< 
CLK_TOP_UNIVPLL1_D2>;
+   assigned-clock-parents = < CLK_TOP_VCODECPLL>,
+< 
CLK_TOP_VCODECPLL_370P5>;
};
 
jpegdec: jpegdec@18004000 {
-- 
2.26.2.526.g744177e7f7-goog



Re: [PATCH] random: inform about bootloader-provided randomness

2019-10-15 Thread Hsin-Yi Wang
On Tue, Oct 15, 2019 at 8:40 AM Will Deacon  wrote:
>
> On Sat, Oct 05, 2019 at 01:36:32PM +0200, Dominik Brodowski wrote:
> > Inform how many bits of randomness were provided by the bootloader,
> > and whether we trust that input.
> >
> > Signed-off-by: Dominik Brodowski 
> > Cc: Ard Biesheuvel 
> > Cc: Hsin-Yi Wang 
> > Cc: Stephen Boyd 
> > Cc: Rob Herring 
> > Cc: Theodore Ts'o 
> > Cc: Will Deacon 
> >
> > diff --git a/drivers/char/random.c b/drivers/char/random.c
> > index de434feb873a..673375e05c0d 100644
> > --- a/drivers/char/random.c
> > +++ b/drivers/char/random.c
> > @@ -2515,6 +2515,10 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
> >   */
> >  void add_bootloader_randomness(const void *buf, unsigned int size)
> >  {
> > + pr_notice("random: adding %u bits of %sbootloader-provided 
> > randomness",
> > + size * 8,
> > + IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER) ? "trusted " : "");
> > +
> >   if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
> >   add_hwgenerator_randomness(buf, size, size * 8);
> >   else
>
> Looks fine to me:
>
> Acked-by: Will Deacon 
>
> Will

Thanks.

Acked-by: Hsin-Yi Wang 


[PATCH RFC v2] reboot: hotplug cpus in migrate_to_reboot_cpu()

2019-10-09 Thread Hsin-Yi Wang
Currently system reboots would use arch specific codes (eg. smp_send_stop)
to offline non reboot cpus. Some arch like arm64, arm, and x86... would set
offline masks to cpu without really offline them. Thus causing some race
condition and kernel warning comes out sometimes when system reboots. We
can do cpu hotplug in migrate_to_reboot_cpu() to avoid this issue.

Signed-off-by: Hsin-Yi Wang 
---
change log:
v1 --> v2:
Call hotplug function in #ifdef CONFIG instead of IS_ENABLED.
(Reported-by: kbuild test robot )

kernel warnings at reboot:
[1] https://lore.kernel.org/lkml/20190820100843.3028-1-hsi...@chromium.org/
[2] https://lore.kernel.org/lkml/20190727164450.ga11...@roeck-us.net/
---
 include/linux/cpu.h |  1 +
 kernel/cpu.c| 17 +
 kernel/reboot.c |  8 ++--
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index d0633ebdaa9c..20a4036f24ad 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -113,6 +113,7 @@ extern void cpu_hotplug_disable(void);
 extern void cpu_hotplug_enable(void);
 void clear_tasks_mm_cpumask(int cpu);
 int cpu_down(unsigned int cpu);
+extern void offline_secondary_cpus(int primary);
 
 #else /* CONFIG_HOTPLUG_CPU */
 
diff --git a/kernel/cpu.c b/kernel/cpu.c
index fc28e17940e0..00b2be6a662d 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1058,6 +1058,23 @@ int cpu_down(unsigned int cpu)
 }
 EXPORT_SYMBOL(cpu_down);
 
+void offline_secondary_cpus(int primary)
+{
+   int i, err;
+
+   cpu_maps_update_begin();
+
+   for_each_online_cpu(i) {
+   if (i == primary)
+   continue;
+   err = _cpu_down(i, 0, CPUHP_OFFLINE);
+   if (err)
+   pr_warn("Failed to offline cpu %d\n", i);
+   }
+   cpu_hotplug_disabled++;
+
+   cpu_maps_update_done();
+}
 #else
 #define takedown_cpu   NULL
 #endif /*CONFIG_HOTPLUG_CPU*/
diff --git a/kernel/reboot.c b/kernel/reboot.c
index c4d472b7f1b4..fdf6730f8a64 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt)"reboot: " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -220,8 +221,6 @@ void migrate_to_reboot_cpu(void)
/* The boot cpu is always logical cpu 0 */
int cpu = reboot_cpu;
 
-   cpu_hotplug_disable();
-
/* Make certain the cpu I'm about to reboot on is online */
if (!cpu_online(cpu))
cpu = cpumask_first(cpu_online_mask);
@@ -231,6 +230,11 @@ void migrate_to_reboot_cpu(void)
 
/* Make certain I only run on the appropriate processor */
set_cpus_allowed_ptr(current, cpumask_of(cpu));
+
+   /* Hotplug other cpus if possible */
+#ifdef CONFIG_HOTPLUG_CPU
+   offline_secondary_cpus(cpu);
+#endif
 }
 
 /**
-- 
2.23.0.700.g56cf767bdb-goog



Re: [PATCH] thermal-generic-adc: Silent error message for EPROBE_DEFER

2019-10-07 Thread Hsin-Yi Wang
On Tue, Sep 10, 2019 at 12:59 AM Hsin-Yi Wang  wrote:
>
> If devm_iio_channel_get() or devm_thermal_zone_of_sensor_register()
> fail with EPROBE_DEFER, we shouldn't print an error message, as the
> device will be probed again later.
>
> Signed-off-by: Hsin-Yi Wang 
> ---

Ping on the thread. Any suggestion for this patch?
Thanks


Re: [PATCH RFC] reboot: hotplug cpus in migrate_to_reboot_cpu()

2019-10-02 Thread Hsin-Yi Wang
On Wed, Oct 2, 2019 at 7:41 PM Hsin-Yi Wang  wrote:
>
> Currently system reboots use arch specific codes (eg. smp_send_stop) to
> offline non reboot cpus. Some arch like arm64, arm, and x86... set offline
> masks to cpu without really offlining them. Thus it causes some race
> condition and kernel warning comes out sometimes when system reboots. We
> can do cpu hotplug in migrate_to_reboot_cpu() to avoid this issue.
>
> Signed-off-by: Hsin-Yi Wang 
> ---
> kernel warnings at reboot:
> [1] https://lore.kernel.org/lkml/20190820100843.3028-1-hsi...@chromium.org/
> [2] https://lore.kernel.org/lkml/20190727164450.ga11...@roeck-us.net/
> ---
>  kernel/cpu.c| 35 +++
>  kernel/reboot.c | 18 --
>  2 files changed, 35 insertions(+), 18 deletions(-)
>
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index fc28e17940e0..2f4d51fe91e3 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -31,6 +31,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>  #define CREATE_TRACE_POINTS
> @@ -1366,6 +1367,40 @@ int __boot_cpu_id;
>
>  #endif /* CONFIG_SMP */
>
> +void migrate_to_reboot_cpu(void)
> +{
> +   /* The boot cpu is always logical cpu 0 */
> +   int cpu = reboot_cpu;
> +
> +   /* Make certain the cpu I'm about to reboot on is online */
> +   if (!cpu_online(cpu))
> +   cpu = cpumask_first(cpu_online_mask);
> +
> +   /* Prevent races with other tasks migrating this task */
> +   current->flags |= PF_NO_SETAFFINITY;
> +
> +   /* Make certain I only run on the appropriate processor */
> +   set_cpus_allowed_ptr(current, cpumask_of(cpu));
> +
> +   /* Hotplug other cpus if possible */
> +   if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {

Should use #ifdef CONFIG_HOTPLUG_CPU here. Will fix in the next
version if this patch is reasonable.
(Reported-by: kbuild test robot )
> +   int i, err;
> +
> +   cpu_maps_update_begin();
> +
> +   for_each_online_cpu(i) {
> +   if (i == cpu)
> +   continue;
> +   err = _cpu_down(i, 0, CPUHP_OFFLINE);
> +   if (err)
> +   pr_info("Failed to offline cpu %d\n", i);
> +   }
> +   cpu_hotplug_disabled++;
> +
> +   cpu_maps_update_done();
> +   }
> +}
> +
>  /* Boot processor state steps */
>  static struct cpuhp_step cpuhp_hp_states[] = {
> [CPUHP_OFFLINE] = {
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index c4d472b7f1b4..f0046be34a60 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -215,24 +215,6 @@ void do_kernel_restart(char *cmd)
> atomic_notifier_call_chain(_handler_list, reboot_mode, cmd);
>  }
>
> -void migrate_to_reboot_cpu(void)
> -{
> -   /* The boot cpu is always logical cpu 0 */
> -   int cpu = reboot_cpu;
> -
> -   cpu_hotplug_disable();
> -
> -   /* Make certain the cpu I'm about to reboot on is online */
> -   if (!cpu_online(cpu))
> -   cpu = cpumask_first(cpu_online_mask);
> -
> -   /* Prevent races with other tasks migrating this task */
> -   current->flags |= PF_NO_SETAFFINITY;
> -
> -   /* Make certain I only run on the appropriate processor */
> -   set_cpus_allowed_ptr(current, cpumask_of(cpu));
> -}
> -
>  /**
>   * kernel_restart - reboot the system
>   * @cmd: pointer to buffer containing command to execute for restart
> --
> 2.23.0.444.g18eeb5a265-goog
>


[PATCH RFC] reboot: hotplug cpus in migrate_to_reboot_cpu()

2019-10-02 Thread Hsin-Yi Wang
Currently system reboots use arch specific codes (eg. smp_send_stop) to
offline non reboot cpus. Some arch like arm64, arm, and x86... set offline
masks to cpu without really offlining them. Thus it causes some race
condition and kernel warning comes out sometimes when system reboots. We
can do cpu hotplug in migrate_to_reboot_cpu() to avoid this issue.

Signed-off-by: Hsin-Yi Wang 
---
kernel warnings at reboot:
[1] https://lore.kernel.org/lkml/20190820100843.3028-1-hsi...@chromium.org/
[2] https://lore.kernel.org/lkml/20190727164450.ga11...@roeck-us.net/
---
 kernel/cpu.c| 35 +++
 kernel/reboot.c | 18 --
 2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index fc28e17940e0..2f4d51fe91e3 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #define CREATE_TRACE_POINTS
@@ -1366,6 +1367,40 @@ int __boot_cpu_id;
 
 #endif /* CONFIG_SMP */
 
+void migrate_to_reboot_cpu(void)
+{
+   /* The boot cpu is always logical cpu 0 */
+   int cpu = reboot_cpu;
+
+   /* Make certain the cpu I'm about to reboot on is online */
+   if (!cpu_online(cpu))
+   cpu = cpumask_first(cpu_online_mask);
+
+   /* Prevent races with other tasks migrating this task */
+   current->flags |= PF_NO_SETAFFINITY;
+
+   /* Make certain I only run on the appropriate processor */
+   set_cpus_allowed_ptr(current, cpumask_of(cpu));
+
+   /* Hotplug other cpus if possible */
+   if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
+   int i, err;
+
+   cpu_maps_update_begin();
+
+   for_each_online_cpu(i) {
+   if (i == cpu)
+   continue;
+   err = _cpu_down(i, 0, CPUHP_OFFLINE);
+   if (err)
+   pr_info("Failed to offline cpu %d\n", i);
+   }
+   cpu_hotplug_disabled++;
+
+   cpu_maps_update_done();
+   }
+}
+
 /* Boot processor state steps */
 static struct cpuhp_step cpuhp_hp_states[] = {
[CPUHP_OFFLINE] = {
diff --git a/kernel/reboot.c b/kernel/reboot.c
index c4d472b7f1b4..f0046be34a60 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -215,24 +215,6 @@ void do_kernel_restart(char *cmd)
atomic_notifier_call_chain(_handler_list, reboot_mode, cmd);
 }
 
-void migrate_to_reboot_cpu(void)
-{
-   /* The boot cpu is always logical cpu 0 */
-   int cpu = reboot_cpu;
-
-   cpu_hotplug_disable();
-
-   /* Make certain the cpu I'm about to reboot on is online */
-   if (!cpu_online(cpu))
-   cpu = cpumask_first(cpu_online_mask);
-
-   /* Prevent races with other tasks migrating this task */
-   current->flags |= PF_NO_SETAFFINITY;
-
-   /* Make certain I only run on the appropriate processor */
-   set_cpus_allowed_ptr(current, cpumask_of(cpu));
-}
-
 /**
  * kernel_restart - reboot the system
  * @cmd: pointer to buffer containing command to execute for restart
-- 
2.23.0.444.g18eeb5a265-goog



Re: [PATCH v2] i2c: i2c-mt65xx: fix NULL ptr dereference

2019-09-30 Thread Hsin-Yi Wang
On Mon, Sep 30, 2019 at 2:20 PM Cengiz Can  wrote:
>
> On 2019-09-30 18:28, Fabien Parent wrote:
> > Fixes: abf4923e97c3 ("i2c: mediatek: disable zero-length transfers for
> > mt8183")
> > Signed-off-by: Fabien Parent 
>
> Reviewed-by: Cengiz Can 
Reviewed-by: Hsin-Yi Wang 

Thanks!


[PATCH] thermal-generic-adc: Silent error message for EPROBE_DEFER

2019-09-10 Thread Hsin-Yi Wang
If devm_iio_channel_get() or devm_thermal_zone_of_sensor_register()
fail with EPROBE_DEFER, we shouldn't print an error message, as the
device will be probed again later.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/thermal/thermal-generic-adc.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/thermal-generic-adc.c 
b/drivers/thermal/thermal-generic-adc.c
index dcecf2e8dc8e..ae5743c9a894 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -134,7 +134,8 @@ static int gadc_thermal_probe(struct platform_device *pdev)
gti->channel = devm_iio_channel_get(>dev, "sensor-channel");
if (IS_ERR(gti->channel)) {
ret = PTR_ERR(gti->channel);
-   dev_err(>dev, "IIO channel not found: %d\n", ret);
+   if (ret != -EPROBE_DEFER)
+   dev_err(>dev, "IIO channel not found: %d\n", ret);
return ret;
}
 
@@ -142,8 +143,10 @@ static int gadc_thermal_probe(struct platform_device *pdev)
   _thermal_ops);
if (IS_ERR(gti->tz_dev)) {
ret = PTR_ERR(gti->tz_dev);
-   dev_err(>dev, "Thermal zone sensor register failed: %d\n",
-   ret);
+   if (ret != -EPROBE_DEFER)
+   dev_err(>dev,
+   "Thermal zone sensor register failed: %d\n",
+   ret);
return ret;
}
 
-- 
2.23.0.162.g0b9fbb3734-goog



Re: [PATCH v2 7/8] thermal: mediatek: add another get_temp ops for thermal sensors

2019-09-09 Thread Hsin-Yi Wang
On Fri, May 10, 2019 at 9:27 PM michael.kao  wrote:
>
> From: Michael Kao 
>
> Provide thermal zone to read thermal sensor
> in the SoC. We can read all the thermal sensors
> value in the SoC by the node /sys/class/thermal/
>
> Signed-off-by: Michael Kao 
> ---
>  drivers/thermal/mtk_thermal.c | 68 
> ++-
>  1 file changed, 60 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index cb41e46..d5c78b0 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -230,6 +230,11 @@ enum {
>
>  struct mtk_thermal;
>
> +struct mtk_thermal_zone {
> +   struct mtk_thermal *mt;
> +   int id;
> +};
> +
>  struct thermal_bank_cfg {
> unsigned int num_sensors;
> const int *sensors;
> @@ -612,7 +617,7 @@ static int mtk_thermal_bank_temperature(struct 
> mtk_thermal_bank *bank)
>  * not immediately shut down.
>  */
> if (temp > 20)
> -   temp = 0;
> +   temp = -EACCES;
Should we return -EAGAIN here? Otherwise there would be warning:
[0.344167] thermal thermal_zone5: failed to read out thermal zone (-13)

Since first read is bogus value, I think EAGAIN also makes sense here.
>
> if (temp > max)
> max = temp;
> @@ -623,7 +628,8 @@ static int mtk_thermal_bank_temperature(struct 
> mtk_thermal_bank *bank)
>
>  static int mtk_read_temp(void *data, int *temperature)
>  {
> -   struct mtk_thermal *mt = data;
> +   struct mtk_thermal_zone *tz = data;
> +   struct mtk_thermal *mt = tz->mt;
> int i;
> int tempmax = INT_MIN;
>
> @@ -636,16 +642,48 @@ static int mtk_read_temp(void *data, int *temperature)
>
> mtk_thermal_put_bank(bank);
> }
> -
> *temperature = tempmax;
>
> return 0;
>  }
>
> +static int mtk_read_sensor_temp(void *data, int *temperature)
> +{
> +   struct mtk_thermal_zone *tz = data;
> +   struct mtk_thermal *mt = tz->mt;
> +   const struct mtk_thermal_data *conf = mt->conf;
> +   int id = tz->id - 1;
> +   int temp = INT_MIN;
> +   u32 raw;
> +
> +   if (id < 0)
> +   return  -EACCES;
> +
> +   raw = readl(mt->thermal_base + conf->msr[id]);
> +
> +   temp = raw_to_mcelsius(mt, id, raw);
> +
> +   /*
> +* The first read of a sensor often contains very high bogus
> +* temperature value. Filter these out so that the system does
> +* not immediately shut down.
> +*/
> +
> +   if (temp > 20)
> +   return  -EACCES;
Same here.
> +
> +   *temperature = temp;
> +   return 0;
> +}
> +
>  static const struct thermal_zone_of_device_ops mtk_thermal_ops = {
> .get_temp = mtk_read_temp,
>  };
>
> +static const struct thermal_zone_of_device_ops mtk_thermal_sensor_ops = {
> +   .get_temp = mtk_read_sensor_temp,
> +};
> +
>  static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
>   u32 apmixed_phys_base, u32 auxadc_phys_base,
>   int ctrl_id)
> @@ -878,6 +916,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
> struct resource *res;
> u64 auxadc_phys_base, apmixed_phys_base;
> struct thermal_zone_device *tzdev;
> +   struct mtk_thermal_zone *tz;
>
> mt = devm_kzalloc(>dev, sizeof(*mt), GFP_KERNEL);
> if (!mt)
> @@ -959,11 +998,24 @@ static int mtk_thermal_probe(struct platform_device 
> *pdev)
>
> platform_set_drvdata(pdev, mt);
>
> -   tzdev = devm_thermal_zone_of_sensor_register(>dev, 0, mt,
> -_thermal_ops);
> -   if (IS_ERR(tzdev)) {
> -   ret = PTR_ERR(tzdev);
> -   goto err_disable_clk_peri_therm;
> +   for (i = 0; i < mt->conf->num_sensors + 1; i++) {
> +   tz = kmalloc(sizeof(*tz), GFP_KERNEL);
> +   if (!tz)
> +   return -ENOMEM;
> +
> +   tz->mt = mt;
> +   tz->id = i;
> +
> +   tzdev = devm_thermal_zone_of_sensor_register(>dev, i,
> +   tz, (i == 0) ?
> +   _thermal_ops : _thermal_sensor_ops);
> +
> +   if (IS_ERR(tzdev)) {
> +   if (IS_ERR(tzdev) != -EACCES) {
> +   ret = PTR_ERR(tzdev);
> +   goto err_disable_clk_peri_therm;
> +   }
> +   }
> }
>
> return 0;
> --
> 2.6.4
>


Re: [PATCH v9 2/3] fdt: add support for rng-seed

2019-08-29 Thread Hsin-Yi Wang
On Thu, Aug 29, 2019 at 1:36 AM Kees Cook  wrote:
>
> Can this please be a boot param (with the default controlled by the
> CONFIG)? See how CONFIG_RANDOM_TRUST_CPU is wired up...
>
> -Kees
>

Currently rng-seed read and added in setup_arch() -->
setup_machine_fdt().. -> early_init_dt_scan_chosen(), which is earlier
than parse_early_param() that initializes early_param.

If we want to set it as a boot param, add_bootloader_randomness() can
only be called after parse_early_param(). The seed can't be directly
added to pool after it's read in. We need to store into global
variable and load it later.
If this seems okay then I'll add a patch for this. Thanks

--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1096,13 +1096,15 @@ static const char *config_cmdline = CONFIG_CMDLINE;

+const void* rng_seed;
+int rng_seed_len;
+
 int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth,
void *data)
 {
int l = 0;
const char *p = NULL;
char *cmdline = data;
-   const void *rng_seed;

  pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);

@@ -1137,10 +1139,8 @@ int __init early_init_dt_scan_chosen(unsigned
long node, const char *uname,

 pr_debug("Command line is: %s\n", (char*)data);

-rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
-if (rng_seed && l > 0) {
-add_bootloader_randomness(rng_seed, l);  //
Originally it's added to entropy pool here
-
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", _seed_len);
+   if (rng_seed && rng_seed_len > 0) {
/* try to clear seed so it won't be found. */

diff --git a/include/linux/random.h b/include/linux/random.h
index 831a002a1882..946840bba7c1 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -31,6 +31,15 @@ static inline void add_latent_entropy(void)
 static inline void add_latent_entropy(void) {}
 #endif

+extern const void* rng_seed;
+extern int rng_seed_len;
+
+static inline void add_bootloader_entropy(void)
+{
+if (rng_seed && rng_seed_len > 0)
+add_bootloader_randomness(rng_seed, rng_seed_len);
+}
+
 extern void add_input_randomness(unsigned int type, unsigned int code,
  unsigned int value) __latent_entropy;
 extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
diff --git a/init/main.c b/init/main.c
index 71847af32e4e..f74a8c7b34af 100644
--- a/init/main.c
+++ b/init/main.c
@@ -645,6 +645,7 @@ asmlinkage __visible void __init start_kernel(void)
  * - adding command line entropy
  */
  rand_initialize();
+ add_bootloader_entropy();
  add_latent_entropy();
  add_device_randomness(command_line, strlen(command_line));
  boot_init_stack_canary();


Re: [PATCH v2] i2c: mediatek: disable zero-length transfers for mt8183

2019-08-23 Thread Hsin-Yi Wang
On Fri, Aug 23, 2019 at 4:09 PM Qii Wang  wrote:

> >
> >  static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
> >  {
> > - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
> > + if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN)
> > + return I2C_FUNC_I2C |
> > + (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
> > + else
> > + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
>
> It can be removed?
See previous discussion: https://patchwork.kernel.org/patch/10814391/#22484435
but not all SoC's quirks has I2C_AQ_NO_ZERO_LEN.


[PATCH v10 3/3] arm64: kexec_file: add rng-seed support

2019-08-23 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
No change since v7
---
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index ba78ee7ca990..7b08bf9499b6 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   u8 rng_seed[RNG_SEED_SIZE];
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   if (ret)
+   goto out;
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH v10 2/3] fdt: add support for rng-seed

2019-08-23 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Obtain of_fdt_crc32 for CRC check after early_init_dt_scan_nodes(),
since early_init_dt_scan_chosen() would modify fdt to erase rng-seed.

Add a new interface add_bootloader_randomness() for rng-seed use case.
Depends on whether the seed is trustworthy, rng seed would be passed to
add_hwgenerator_randomness(). Otherwise it would be passed to
add_device_randomness(). Decision is controlled by kernel config
RANDOM_TRUST_BOOTLOADER.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Rob Herring 
---
Change from v9:
* reword kconfig
* use IS_ENABLED for config
---
 drivers/char/Kconfig   |  9 +
 drivers/char/random.c  | 14 ++
 drivers/of/fdt.c   | 14 --
 include/linux/random.h |  1 +
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 96156c729a31..df0fc997dc3e 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -551,3 +551,12 @@ config RANDOM_TRUST_CPU
has not installed a hidden back door to compromise the CPU's
random number generation facilities. This can also be configured
at boot with "random.trust_cpu=on/off".
+
+config RANDOM_TRUST_BOOTLOADER
+   bool "Trust the bootloader to initialize Linux's CRNG"
+   help
+   Some bootloaders can provide entropy to increase the kernel's initial
+   device randomness. Say Y here to assume the entropy provided by the
+   booloader is trustworthy so it will be added to the kernel's entropy
+   pool. Otherwise, say N here so it will be regarded as device input that
+   only mixes the entropy pool.
\ No newline at end of file
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 5d5ea4ce1442..566922df4b7b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2445,3 +2445,17 @@ void add_hwgenerator_randomness(const char *buffer, 
size_t count,
credit_entropy_bits(poolp, entropy);
 }
 EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
+
+/* Handle random seed passed by bootloader.
+ * If the seed is trustworthy, it would be regarded as hardware RNGs. Otherwise
+ * it would be regarded as device data.
+ * The decision is controlled by CONFIG_RANDOM_TRUST_BOOTLOADER.
+ */
+void add_bootloader_randomness(const void *buf, unsigned int size)
+{
+   if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER))
+   add_hwgenerator_randomness(buf, size, size * 8);
+   else
+   add_device_randomness(buf, size);
+}
+EXPORT_SYMBOL_GPL(add_bootloader_randomness);
\ No newline at end of file
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9cdf14b9aaab..7d97ab6d0e31 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1044,6 +1045,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1078,6 +1080,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_bootloader_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
@@ -1166,8 +1176,6 @@ bool __init early_init_dt_verify(void *params)
 
/* Setup flat device-tree pointer */
initial_boot_params = params;
-   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
-   fdt_totalsize(initial_boot_params));
return true;
 }
 
@@ -1197,6 +1205,8 @@ bool __init early_init_dt_scan(void *params)
return false;
 
early_init_dt_scan_nodes();
+   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
+   fdt_totalsize(initial_boot_params));
return true;
 }
 
diff --git a/include/linux/random.h b/include/linux/random.h
index 1f7dced2bba6..f189c927fdea 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -19,6 +19,7 @@ struct random_ready_callback {
 };
 
 extern void add_device_randomness(const void *, unsigned int);
+extern void add_bootloader_randomness(const void *, unsigned int);
 
 #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
 static inline void add_latent_entropy(void)
-- 
2.20.1



[PATCH v10 1/3] arm64: map FDT as RW for early_init_dt_scan()

2019-08-23 Thread Hsin-Yi Wang
Currently in arm64, FDT is mapped to RO before it's passed to
early_init_dt_scan(). However, there might be some codes
(eg. commit "fdt: add support for rng-seed") that need to modify FDT
during init. Map FDT to RO after early fixups are done.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Mike Rapoport 
---
No change since v7
---
 arch/arm64/include/asm/mmu.h |  2 +-
 arch/arm64/kernel/kaslr.c|  5 +
 arch/arm64/kernel/setup.c|  9 -
 arch/arm64/mm/mmu.c  | 15 +--
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h
index fd6161336653..f217e3292919 100644
--- a/arch/arm64/include/asm/mmu.h
+++ b/arch/arm64/include/asm/mmu.h
@@ -126,7 +126,7 @@ extern void init_mem_pgprot(void);
 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
   unsigned long virt, phys_addr_t size,
   pgprot_t prot, bool page_mappings_only);
-extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
+extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
 extern void mark_linear_text_alias_ro(void);
 
 #define INIT_MM_CONTEXT(name)  \
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 5a59f7567f9c..416f537bf614 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt)
return default_cmdline;
 }
 
-extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
-  pgprot_t prot);
-
 /*
  * This routine will be executed with the kernel mapped at its default virtual
  * address, and if it returns successfully, the kernel will be remapped, and
@@ -93,7 +90,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
 * attempt at mapping the FDT in setup_machine()
 */
early_fixmap_init();
-   fdt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
+   fdt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
if (!fdt)
return 0;
 
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 57ff38600828..56f664561754 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void)
 
 static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
-   void *dt_virt = fixmap_remap_fdt(dt_phys);
+   int size;
+   void *dt_virt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
const char *name;
 
+   if (dt_virt)
+   memblock_reserve(dt_phys, size);
+
if (!dt_virt || !early_init_dt_scan(dt_virt)) {
pr_crit("\n"
"Error: invalid device tree blob at physical address 
%pa (virtual address 0x%p)\n"
@@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}
 
+   /* Early fixups are done, map the FDT as read-only now */
+   fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
+
name = of_flat_dt_get_machine_name();
if (!name)
return;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e67bab4d613e..1586d7fbf26a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -877,7 +877,7 @@ void __set_fixmap(enum fixed_addresses idx,
}
 }
 
-void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
+void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 {
const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
int offset;
@@ -930,19 +930,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
-{
-   void *dt_virt;
-   int size;
-
-   dt_virt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
-   if (!dt_virt)
-   return NULL;
-
-   memblock_reserve(dt_phys, size);
-   return dt_virt;
-}
-
 int __init arch_ioremap_p4d_supported(void)
 {
return 0;
-- 
2.20.1



[PATCH v10 0/3] add support for rng-seed

2019-08-23 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. This can be used for adding sufficient initial entropy
for stack canary. Especially architectures that lack per-stack canary.

Hsin-Yi Wang (3):
  arm64: map FDT as RW for early_init_dt_scan()
  fdt: add support for rng-seed
  arm64: kexec_file: add rng-seed support

 arch/arm64/include/asm/mmu.h   |  2 +-
 arch/arm64/kernel/kaslr.c  |  5 +
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 arch/arm64/kernel/setup.c  |  9 -
 arch/arm64/mm/mmu.c| 15 +--
 drivers/char/Kconfig   |  9 +
 drivers/char/random.c  | 14 ++
 drivers/of/fdt.c   | 14 --
 include/linux/random.h |  1 +
 9 files changed, 64 insertions(+), 23 deletions(-)

-- 
2.20.1



[PATCH v2] i2c: mediatek: disable zero-length transfers for mt8183

2019-08-22 Thread Hsin-Yi Wang
When doing i2cdetect quick write mode, we would get transfer
error ENOMEM, and i2cdetect shows there's no device at the address.
Quoting from mt8183 datasheet, the number of transfers to be
transferred in one transaction should be set to bigger than 1,
so we should forbid zero-length transfer and update functionality.

Incorrect return:
localhost ~ # i2cdetect -q -y 0
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:  -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

After this patch:
localhost ~ #  i2cdetect -q -y 0
Error: Can't use SMBus Quick Write command on this bus

localhost ~ #  i2cdetect -y 0
Warning: Can't use SMBus Quick Write command, will skip some addresses
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:
10:
20:
30: -- -- -- -- -- -- -- --
40:
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60:
70:

Reported-by: Alexandru M Stan 
Signed-off-by: Hsin-Yi Wang 
---
Change from v1:
* restore the order of algo and quirks
---
 drivers/i2c/busses/i2c-mt65xx.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 252edb433fdf..29eae1bf4f86 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -234,6 +234,10 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = 
{
.max_num_msgs = 255,
 };
 
+static const struct i2c_adapter_quirks mt8183_i2c_quirks = {
+   .flags = I2C_AQ_NO_ZERO_LEN,
+};
+
 static const struct mtk_i2c_compatible mt2712_compat = {
.regs = mt_i2c_regs_v1,
.pmic_i2c = 0,
@@ -298,6 +302,7 @@ static const struct mtk_i2c_compatible mt8173_compat = {
 };
 
 static const struct mtk_i2c_compatible mt8183_compat = {
+   .quirks = _i2c_quirks,
.regs = mt_i2c_regs_v2,
.pmic_i2c = 0,
.dcm = 0,
@@ -870,7 +875,11 @@ static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id)
 
 static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
 {
-   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+   if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN)
+   return I2C_FUNC_I2C |
+   (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
+   else
+   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
 static const struct i2c_algorithm mtk_i2c_algorithm = {
-- 
2.20.1



Re: [PATCH RESEND] i2c: mediatek: disable zero-length transfers for mt8183

2019-08-22 Thread Hsin-Yi Wang
On Thu, Aug 22, 2019 at 5:24 PM Yingjoe Chen  wrote:
>
> Why do you need to change this part?
>
> Joe.C
>
You're right. We don't need to change this. I'll revert this back.


[PATCH v9 3/3] arm64: kexec_file: add rng-seed support

2019-08-22 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
No change since v7.
---
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index ba78ee7ca990..7b08bf9499b6 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   u8 rng_seed[RNG_SEED_SIZE];
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   if (ret)
+   goto out;
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH v9 2/3] fdt: add support for rng-seed

2019-08-22 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Obtain of_fdt_crc32 for CRC check after early_init_dt_scan_nodes(),
since early_init_dt_scan_chosen() would modify fdt to erase rng-seed.

Add a new interface add_bootloader_randomness() for rng-seed use case.
Depends on whether the seed is trustworthy, rng seed would be passed to
add_hwgenerator_randomness(). Otherwise it would be passed to
add_device_randomness(). Decision is controlled by kernel config
RANDOM_TRUST_BOOTLOADER.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Rob Herring 
---
Change from v8:
* Add a new interface add_bootloader_randomness
* Add a new kernel config
---
 drivers/char/Kconfig   | 10 ++
 drivers/char/random.c  | 15 +++
 drivers/of/fdt.c   | 14 --
 include/linux/random.h |  1 +
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 96156c729a31..5974a5906fd0 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -551,3 +551,13 @@ config RANDOM_TRUST_CPU
has not installed a hidden back door to compromise the CPU's
random number generation facilities. This can also be configured
at boot with "random.trust_cpu=on/off".
+
+config RANDOM_TRUST_BOOTLOADER
+   bool "Trust the bootloader to initialize Linux's CRNG"
+   default n
+   help
+   Bootloader could provide rng-seed set in /chosen/rng-seed in DT to help
+   increase initial device randomness. Assume the entropy provided is
+   trustworthy, it would be regarded as true hardware RNGs and update the
+   entropy estimate. Otherwise it would be regarded as device input that
+   could help mix the entropy pool, but won't be added to actual entropy.
\ No newline at end of file
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 5d5ea4ce1442..29d3ff3de1e1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2445,3 +2445,18 @@ void add_hwgenerator_randomness(const char *buffer, 
size_t count,
credit_entropy_bits(poolp, entropy);
 }
 EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
+
+/* Handle random seed passed by bootloader.
+ * If the seed is trustworthy, it would be regarded as hardware RNGs. Otherwise
+ * it would be regarded as device data.
+ * The decision is controlled by CONFIG_RANDOM_TRUST_BOOTLOADER.
+ */
+void add_bootloader_randomness(const void *buf, unsigned int size)
+{
+#ifdef CONFIG_RANDOM_TRUST_BOOTLOADER
+   add_hwgenerator_randomness(buf, size, size * 8);
+#else
+   add_device_randomness(buf, size);
+#endif
+}
+EXPORT_SYMBOL_GPL(add_bootloader_randomness);
\ No newline at end of file
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9cdf14b9aaab..7d97ab6d0e31 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1044,6 +1045,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1078,6 +1080,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_bootloader_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
@@ -1166,8 +1176,6 @@ bool __init early_init_dt_verify(void *params)
 
/* Setup flat device-tree pointer */
initial_boot_params = params;
-   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
-   fdt_totalsize(initial_boot_params));
return true;
 }
 
@@ -1197,6 +1205,8 @@ bool __init early_init_dt_scan(void *params)
return false;
 
early_init_dt_scan_nodes();
+   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
+   fdt_totalsize(initial_boot_params));
return true;
 }
 
diff --git a/include/linux/random.h b/include/linux/random.h
index 1f7dced2bba6..f189c927fdea 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -19,6 +19,7 @@ struct random_ready_callback {
 };
 
 extern void add_device_randomness(const void *, unsigned int);
+extern void add_bootloader_randomness(const void *, unsigned int);
 
 #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
 static inline void add_latent_entropy(void)
-- 
2.20.1



[PATCH v9 1/3] arm64: map FDT as RW for early_init_dt_scan()

2019-08-22 Thread Hsin-Yi Wang
Currently in arm64, FDT is mapped to RO before it's passed to
early_init_dt_scan(). However, there might be some codes
(eg. commit "fdt: add support for rng-seed") that need to modify FDT
during init. Map FDT to RO after early fixups are done.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Mike Rapoport 
---
No change since v7.
---
 arch/arm64/include/asm/mmu.h |  2 +-
 arch/arm64/kernel/kaslr.c|  5 +
 arch/arm64/kernel/setup.c|  9 -
 arch/arm64/mm/mmu.c  | 15 +--
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h
index fd6161336653..f217e3292919 100644
--- a/arch/arm64/include/asm/mmu.h
+++ b/arch/arm64/include/asm/mmu.h
@@ -126,7 +126,7 @@ extern void init_mem_pgprot(void);
 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
   unsigned long virt, phys_addr_t size,
   pgprot_t prot, bool page_mappings_only);
-extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
+extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
 extern void mark_linear_text_alias_ro(void);
 
 #define INIT_MM_CONTEXT(name)  \
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 5a59f7567f9c..416f537bf614 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt)
return default_cmdline;
 }
 
-extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
-  pgprot_t prot);
-
 /*
  * This routine will be executed with the kernel mapped at its default virtual
  * address, and if it returns successfully, the kernel will be remapped, and
@@ -93,7 +90,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
 * attempt at mapping the FDT in setup_machine()
 */
early_fixmap_init();
-   fdt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
+   fdt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
if (!fdt)
return 0;
 
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 57ff38600828..56f664561754 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void)
 
 static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
-   void *dt_virt = fixmap_remap_fdt(dt_phys);
+   int size;
+   void *dt_virt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
const char *name;
 
+   if (dt_virt)
+   memblock_reserve(dt_phys, size);
+
if (!dt_virt || !early_init_dt_scan(dt_virt)) {
pr_crit("\n"
"Error: invalid device tree blob at physical address 
%pa (virtual address 0x%p)\n"
@@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}
 
+   /* Early fixups are done, map the FDT as read-only now */
+   fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
+
name = of_flat_dt_get_machine_name();
if (!name)
return;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e67bab4d613e..1586d7fbf26a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -877,7 +877,7 @@ void __set_fixmap(enum fixed_addresses idx,
}
 }
 
-void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
+void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 {
const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
int offset;
@@ -930,19 +930,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
-{
-   void *dt_virt;
-   int size;
-
-   dt_virt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
-   if (!dt_virt)
-   return NULL;
-
-   memblock_reserve(dt_phys, size);
-   return dt_virt;
-}
-
 int __init arch_ioremap_p4d_supported(void)
 {
return 0;
-- 
2.20.1



[PATCH v9 0/3] add support for rng-seed

2019-08-22 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. This can be used for adding sufficient initial entropy
for stack canary. Especially architectures that lack per-stack canary.

Hsin-Yi Wang (3):
  arm64: map FDT as RW for early_init_dt_scan()
  fdt: add support for rng-seed
  arm64: kexec_file: add rng-seed support

 arch/arm64/include/asm/mmu.h   |  2 +-
 arch/arm64/kernel/kaslr.c  |  5 +
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 arch/arm64/kernel/setup.c  |  9 -
 arch/arm64/mm/mmu.c| 15 +--
 drivers/char/Kconfig   | 10 ++
 drivers/char/random.c  | 15 +++
 drivers/of/fdt.c   | 14 --
 include/linux/random.h |  1 +
 9 files changed, 66 insertions(+), 23 deletions(-)

--
Change from v8:
* Add a new interface add_bootloader_randomness
--
2.20.1



[PATCH RESEND] i2c: mediatek: disable zero-length transfers for mt8183

2019-08-21 Thread Hsin-Yi Wang
When doing i2cdetect quick write mode, we would get transfer
error ENOMEM, and i2cdetect shows there's no device at the address.
Quoting from mt8183 datasheet, the number of transfers to be
transferred in one transaction should be set to bigger than 1,
so we should forbid zero-length transfer and update functionality.

Incorrect return:
localhost ~ # i2cdetect -q -y 0
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:  -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

After this patch:
localhost ~ #  i2cdetect -q -y 0
Error: Can't use SMBus Quick Write command on this bus

localhost ~ #  i2cdetect -y 0
Warning: Can't use SMBus Quick Write command, will skip some addresses
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:
10:
20:
30: -- -- -- -- -- -- -- --
40:
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60:
70:

Reported-by: Alexandru M Stan 
Signed-off-by: Hsin-Yi Wang 
---
Previous patch and discussion:
http://patchwork.ozlabs.org/patch/1042684/
---
 drivers/i2c/busses/i2c-mt65xx.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 252edb433fdf..2842ca4b8c3b 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -234,6 +234,10 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = 
{
.max_num_msgs = 255,
 };
 
+static const struct i2c_adapter_quirks mt8183_i2c_quirks = {
+   .flags = I2C_AQ_NO_ZERO_LEN,
+};
+
 static const struct mtk_i2c_compatible mt2712_compat = {
.regs = mt_i2c_regs_v1,
.pmic_i2c = 0,
@@ -298,6 +302,7 @@ static const struct mtk_i2c_compatible mt8173_compat = {
 };
 
 static const struct mtk_i2c_compatible mt8183_compat = {
+   .quirks = _i2c_quirks,
.regs = mt_i2c_regs_v2,
.pmic_i2c = 0,
.dcm = 0,
@@ -870,7 +875,11 @@ static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id)
 
 static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
 {
-   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+   if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN)
+   return I2C_FUNC_I2C |
+   (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
+   else
+   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
 static const struct i2c_algorithm mtk_i2c_algorithm = {
@@ -933,8 +942,8 @@ static int mtk_i2c_probe(struct platform_device *pdev)
i2c->dev = >dev;
i2c->adap.dev.parent = >dev;
i2c->adap.owner = THIS_MODULE;
-   i2c->adap.algo = _i2c_algorithm;
i2c->adap.quirks = i2c->dev_comp->quirks;
+   i2c->adap.algo = _i2c_algorithm;
i2c->adap.timeout = 2 * HZ;
i2c->adap.retries = 1;
 
-- 
2.20.1



Re: [PATCH v8 2/3] fdt: add support for rng-seed

2019-08-20 Thread Hsin-Yi Wang
Then we'd still use add_device_randomness() in case that bootloader
provides weak entropy.

On Tue, Aug 20, 2019 at 7:14 PM Ard Biesheuvel
 wrote:
>
> On Tue, 20 Aug 2019 at 10:43, Hsin-Yi Wang  wrote:
> >
> > Hi Ted,
> >
> > Thanks for raising this question.
> >
> > For UEFI based system, they have a config table that carries rng seed
> > and can be passed to device randomness. However, they also use
> > add_device_randomness (not sure if it's the same reason that they
> > can't guarantee _all_ bootloader can be trusted)
>
> The config table is actually a Linux invention: it is populated by the
> EFI stub code (which is part of the kernel) based on the output of a
> call into the EFI_RNG_PROTOCOL, which is defined in the UEFI spec, but
> optional and not widely available.
>
> I have opted for add_device_randomness() since there is no way to
> establish the quality level of the output of EFI_RNG_PROTOCOL, and so
> it is currently only used to prevent the bootup state of the entropy
> pool to be too predictable, and the output does not contribute to the
> entropy estimate kept by the RNG core.
>
>
> > This patch is to let DT based system also have similar features, which
> > can make initial random number stronger. (We only care initial
> > situation here, since more entropy would be added to kernel as time
> > goes on )
> >
> > Conservatively, we can use add_device_randomness() as well, which
> > would pass buffer to crng_slow_load() instead of crng_fast_load().
> > But I think we should trust bootloader here. Whoever wants to use this
> > feature should make sure their bootloader can pass valid (random
> > enough) seeds. If they are not sure, they can just don't add the
> > property to DT.
>
> It is the firmware that adds the property to the DT, not the user.


[PATCH RFC] smp: Add cpu unstopped mask for smp_send_stop/stop_other_cpus

2019-08-20 Thread Hsin-Yi Wang
In arm/arm64/x86, reboot IPI function uses CPU online mask to let
primary CPU know how many secondary CPUs it has to wait for in
smp_send_stop()/native_stop_other_cpus().

However, sometimes this would trigger unnecessary warnings, since
interrupts and tasks might fall on a CPU that has already executed
the reboot ipi function. This is fine since CPU is already in spinloop.
But warnings are generated since it finds that the CPU is marked as
offiline. The warnings are supposed to catch failures in normal hotplug
offline CPUs, and reboot isn't a regular hotplug. So instead of reusing
online masks, we should use a new mask in reboot IPI functions to do the
work.

Take tick broadcast for example. If broadcast and smp_send_stop()
happen together, most of the time, the CPU getting earliest broadcast
is already in spinloop and thus won't do anything. If the first
broadcast arrives to CPU that hasn't already executed reboot ipi, it
would try to IPI another CPU, but the CPU is already marked as offline,
and warning comes out:

[   22.481523] reboot: Restarting system
[   22.481608] WARNING: CPU: 4 PID: 0 at ...
.
[   22.481980] Call trace:
[   22.481991]  tick_handle_oneshot_broadcast+0x1f8/0x214
[   22.482003]  mtk_syst_handler+0x34/0x44
[   22.482016]  __handle_irq_event_percpu+0x16c/0x28c
[   22.482026]  handle_irq_event_percpu+0x34/0x8c
[   22.482035]  handle_irq_event+0x48/0x78
[   22.482044]  handle_fasteoi_irq+0xd0/0x1a0
[   22.482054]  __handle_domain_irq+0x84/0xc4
[   22.482065]  gic_handle_irq+0x154/0x1a4
[   22.482073]  el1_irq+0xb0/0x128
[   22.482081]  __do_softirq+0x88/0x2fc
[   22.482091]  irq_exit+0xa0/0xa4
[   22.482101]  handle_IPI+0x1ac/0x2cc
[   22.482109]  gic_handle_irq+0x124/0x1a4
[   22.482117]  el1_irq+0xb0/0x128
[   22.482127]  cpuidle_enter_state+0x298/0x328
[   22.482135]  cpuidle_enter+0x30/0x40
[   22.482146]  do_idle+0x154/0x270
[   22.482154]  cpu_startup_entry+0x24/0x28
[   22.482164]  secondary_start_kernel+0x15c/0x168
[   22.482171] ---[ end trace 25f699b7e87857ff ]---

>From kernel/time/tick-broadcast.c:
  /*
   * Sanity check. Catch the case where we try to broadcast to
   * offline cpus.
   */
  if (WARN_ON_ONCE(!cpumask_subset(tmpmask, cpu_online_mask)))
  cpumask_and(tmpmask, tmpmask, cpu_online_mask);

Signed-off-by: Hsin-Yi Wang 
---
Note
- The warning comes from arm64 device
- Previous related patches
 - https://lkml.org/lkml/2012/8/22/3
 - https://patchwork.kernel.org/patch/10535409/
---
 arch/arm/kernel/smp.c |  9 +
 arch/arm64/kernel/smp.c   | 12 +++-
 arch/x86/kernel/process.c |  2 +-
 arch/x86/kernel/smp.c |  6 +++---
 arch/x86/kernel/smpboot.c |  2 ++
 include/linux/cpumask.h   | 18 ++
 kernel/cpu.c  |  4 
 7 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 4b0bab2607e4..18f90cea05b2 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -245,6 +245,7 @@ int __cpu_disable(void)
 * and we must not schedule until we're ready to give up the cpu.
 */
set_cpu_online(cpu, false);
+   set_cpu_unstopped(cpu, false);
 
/*
 * OK - migrate IRQs away from this CPU
@@ -430,6 +431,7 @@ asmlinkage void secondary_start_kernel(void)
 * before we continue - which happens after __cpu_up returns.
 */
set_cpu_online(cpu, true);
+   set_cpu_unstopped(cpu, true);
 
check_other_bugs();
 
@@ -593,11 +595,10 @@ static void ipi_cpu_stop(unsigned int cpu)
raw_spin_unlock(_lock);
}
 
-   set_cpu_online(cpu, false);
-
local_fiq_disable();
local_irq_disable();
 
+   set_cpu_unstopped(cpu, false);
while (1) {
cpu_relax();
wfe();
@@ -713,10 +714,10 @@ void smp_send_stop(void)
 
/* Wait up to one second for other CPUs to stop */
timeout = USEC_PER_SEC;
-   while (num_online_cpus() > 1 && timeout--)
+   while (num_unstopped_cpus() > 1 && timeout--)
udelay(1);
 
-   if (num_online_cpus() > 1)
+   if (num_unstopped_cpus() > 1)
pr_warn("SMP: failed to stop secondary CPUs\n");
 }
 
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 018a33e01b0e..ff0d9fcf97ed 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -249,6 +249,7 @@ asmlinkage notrace void secondary_start_kernel(void)
 read_cpuid_id());
update_cpu_boot_status(CPU_BOOT_SUCCESS);
set_cpu_online(cpu, true);
+   set_cpu_unstopped(cpu, true);
complete(_running);
 
local_daif_restore(DAIF_PROCCTX);
@@ -299,6 +300,7 @@ int __cpu_disable(void)
 * and we must not schedule until we're ready to give up the cpu.
 */
set_cpu_online(cpu, false);
+   set_cpu_unstopped(cpu, false);
 
/*
 * OK - 

Re: [PATCH v8 2/3] fdt: add support for rng-seed

2019-08-20 Thread Hsin-Yi Wang
Hi Ted,

Thanks for raising this question.

For UEFI based system, they have a config table that carries rng seed
and can be passed to device randomness. However, they also use
add_device_randomness (not sure if it's the same reason that they
can't guarantee _all_ bootloader can be trusted)
This patch is to let DT based system also have similar features, which
can make initial random number stronger. (We only care initial
situation here, since more entropy would be added to kernel as time
goes on )

Conservatively, we can use add_device_randomness() as well, which
would pass buffer to crng_slow_load() instead of crng_fast_load().
But I think we should trust bootloader here. Whoever wants to use this
feature should make sure their bootloader can pass valid (random
enough) seeds. If they are not sure, they can just don't add the
property to DT.


[PATCH v8 3/3] arm64: kexec_file: add rng-seed support

2019-08-19 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
No change after v7.
---
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index ba78ee7ca990..7b08bf9499b6 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   u8 rng_seed[RNG_SEED_SIZE];
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   if (ret)
+   goto out;
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH v8 1/3] arm64: map FDT as RW for early_init_dt_scan()

2019-08-19 Thread Hsin-Yi Wang
Currently in arm64, FDT is mapped to RO before it's passed to
early_init_dt_scan(). However, there might be some codes
(eg. commit "fdt: add support for rng-seed") that need to modify FDT
during init. Map FDT to RO after early fixups are done.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Mike Rapoport 
---
No change from v7.
---
 arch/arm64/include/asm/mmu.h |  2 +-
 arch/arm64/kernel/kaslr.c|  5 +
 arch/arm64/kernel/setup.c|  9 -
 arch/arm64/mm/mmu.c  | 15 +--
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h
index fd6161336653..f217e3292919 100644
--- a/arch/arm64/include/asm/mmu.h
+++ b/arch/arm64/include/asm/mmu.h
@@ -126,7 +126,7 @@ extern void init_mem_pgprot(void);
 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
   unsigned long virt, phys_addr_t size,
   pgprot_t prot, bool page_mappings_only);
-extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
+extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
 extern void mark_linear_text_alias_ro(void);
 
 #define INIT_MM_CONTEXT(name)  \
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 5a59f7567f9c..416f537bf614 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt)
return default_cmdline;
 }
 
-extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
-  pgprot_t prot);
-
 /*
  * This routine will be executed with the kernel mapped at its default virtual
  * address, and if it returns successfully, the kernel will be remapped, and
@@ -93,7 +90,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
 * attempt at mapping the FDT in setup_machine()
 */
early_fixmap_init();
-   fdt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
+   fdt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
if (!fdt)
return 0;
 
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 57ff38600828..56f664561754 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void)
 
 static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
-   void *dt_virt = fixmap_remap_fdt(dt_phys);
+   int size;
+   void *dt_virt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
const char *name;
 
+   if (dt_virt)
+   memblock_reserve(dt_phys, size);
+
if (!dt_virt || !early_init_dt_scan(dt_virt)) {
pr_crit("\n"
"Error: invalid device tree blob at physical address 
%pa (virtual address 0x%p)\n"
@@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}
 
+   /* Early fixups are done, map the FDT as read-only now */
+   fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
+
name = of_flat_dt_get_machine_name();
if (!name)
return;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e67bab4d613e..1586d7fbf26a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -877,7 +877,7 @@ void __set_fixmap(enum fixed_addresses idx,
}
 }
 
-void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
+void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 {
const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
int offset;
@@ -930,19 +930,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
-{
-   void *dt_virt;
-   int size;
-
-   dt_virt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
-   if (!dt_virt)
-   return NULL;
-
-   memblock_reserve(dt_phys, size);
-   return dt_virt;
-}
-
 int __init arch_ioremap_p4d_supported(void)
 {
return 0;
-- 
2.20.1



[PATCH v8 2/3] fdt: add support for rng-seed

2019-08-19 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Obtain of_fdt_crc32 for CRC check after early_init_dt_scan_nodes(),
since early_init_dt_scan_chosen() would modify fdt to erase rng-seed.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Rob Herring 
---
Change from v7:
obtain of_fdt_crc32 after early_init_dt_scan_nodes().
---
 drivers/of/fdt.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9cdf14b9aaab..97a75996993c 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1044,6 +1045,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1078,6 +1080,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_device_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
@@ -1166,8 +1176,6 @@ bool __init early_init_dt_verify(void *params)
 
/* Setup flat device-tree pointer */
initial_boot_params = params;
-   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
-   fdt_totalsize(initial_boot_params));
return true;
 }
 
@@ -1197,6 +1205,8 @@ bool __init early_init_dt_scan(void *params)
return false;
 
early_init_dt_scan_nodes();
+   of_fdt_crc32 = crc32_be(~0, initial_boot_params,
+   fdt_totalsize(initial_boot_params));
return true;
 }
 
-- 
2.20.1



[PATCH v8 0/3] add support for rng-seed

2019-08-19 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. This can be used for adding sufficient initial entropy
for stack canary. Especially architectures that lack per-stack canary.

Hsin-Yi Wang (3):
  arm64: map FDT as RW for early_init_dt_scan()
  fdt: add support for rng-seed
  arm64: kexec_file: add rng-seed support

 arch/arm64/include/asm/mmu.h   |  2 +-
 arch/arm64/kernel/kaslr.c  |  5 +
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 arch/arm64/kernel/setup.c  |  9 -
 arch/arm64/mm/mmu.c| 15 +--
 drivers/of/fdt.c   | 14 --
 6 files changed, 40 insertions(+), 23 deletions(-)

-- 
2.20.1



[PATCH RESEND v7 3/3] arm64: kexec_file: add rng-seed support

2019-08-08 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index ba78ee7ca990..7b08bf9499b6 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   u8 rng_seed[RNG_SEED_SIZE];
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   if (ret)
+   goto out;
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH RESEND v7 2/3] fdt: add support for rng-seed

2019-08-08 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Rob Herring 
---
 drivers/of/fdt.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9cdf14b9aaab..640c817cf65b 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1044,6 +1045,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1078,6 +1080,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_device_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
-- 
2.20.1



[PATCH RESEND v7 1/3] arm64: map FDT as RW for early_init_dt_scan()

2019-08-08 Thread Hsin-Yi Wang
Currently in arm64, FDT is mapped to RO before it's passed to
early_init_dt_scan(). However, there might be some codes
(eg. commit "fdt: add support for rng-seed") that need to modify FDT
during init. Map FDT to RO after early fixups are done.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Mike Rapoport 
---
 arch/arm64/include/asm/mmu.h |  2 +-
 arch/arm64/kernel/kaslr.c|  5 +
 arch/arm64/kernel/setup.c|  9 -
 arch/arm64/mm/mmu.c  | 15 +--
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h
index fd6161336653..f217e3292919 100644
--- a/arch/arm64/include/asm/mmu.h
+++ b/arch/arm64/include/asm/mmu.h
@@ -126,7 +126,7 @@ extern void init_mem_pgprot(void);
 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
   unsigned long virt, phys_addr_t size,
   pgprot_t prot, bool page_mappings_only);
-extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
+extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
 extern void mark_linear_text_alias_ro(void);
 
 #define INIT_MM_CONTEXT(name)  \
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 708051655ad9..d94a3e41cef9 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt)
return default_cmdline;
 }
 
-extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
-  pgprot_t prot);
-
 /*
  * This routine will be executed with the kernel mapped at its default virtual
  * address, and if it returns successfully, the kernel will be remapped, and
@@ -93,7 +90,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
 * attempt at mapping the FDT in setup_machine()
 */
early_fixmap_init();
-   fdt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
+   fdt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
if (!fdt)
return 0;
 
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 9c4bad7d7131..25f5127210f8 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void)
 
 static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
-   void *dt_virt = fixmap_remap_fdt(dt_phys);
+   int size;
+   void *dt_virt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
const char *name;
 
+   if (dt_virt)
+   memblock_reserve(dt_phys, size);
+
if (!dt_virt || !early_init_dt_scan(dt_virt)) {
pr_crit("\n"
"Error: invalid device tree blob at physical address 
%pa (virtual address 0x%p)\n"
@@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}
 
+   /* Early fixups are done, map the FDT as read-only now */
+   fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
+
name = of_flat_dt_get_machine_name();
if (!name)
return;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 63d730c5b7a9..bed9db92be24 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -876,7 +876,7 @@ void __set_fixmap(enum fixed_addresses idx,
}
 }
 
-void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
+void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 {
const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
int offset;
@@ -929,19 +929,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
-{
-   void *dt_virt;
-   int size;
-
-   dt_virt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
-   if (!dt_virt)
-   return NULL;
-
-   memblock_reserve(dt_phys, size);
-   return dt_virt;
-}
-
 int __init arch_ioremap_p4d_supported(void)
 {
return 0;
-- 
2.20.1



[PATCH RESEND v7 0/3] add support for rng-seed

2019-08-08 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. This can be used for adding sufficient initial entropy
for stack canary. Especially architectures that lack per-stack canary.

Hsin-Yi Wang (3):
  arm64: map FDT as RW for early_init_dt_scan()
  fdt: add support for rng-seed
  arm64: kexec_file: add rng-seed support

 arch/arm64/include/asm/mmu.h   |  2 +-
 arch/arm64/kernel/kaslr.c  |  5 +
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 arch/arm64/kernel/setup.c  |  9 -
 arch/arm64/mm/mmu.c| 15 +--
 drivers/of/fdt.c   | 10 ++
 6 files changed, 38 insertions(+), 21 deletions(-)

-- 
2.20.1



Re: [PATCH v7 0/3] add support for rng-seed

2019-08-05 Thread Hsin-Yi Wang
Ping on the thread.
Should the series be proceeded?

Thanks


Re: [PATCH v3 3/5] OPP: Improve require-opps linking

2019-07-30 Thread Hsin-Yi Wang
On Wed, Jul 17, 2019 at 10:23 PM Saravana Kannan  wrote:

> -free_required_tables:
> -   _opp_table_free_required_tables(opp_table);
> -put_np:
> -   of_node_put(np);
> +   for (i = 0; i < src->required_opp_count; i++) {
> +   if (src->required_opp_tables[i])
> +   continue;
> +
> +   req_np = of_parse_required_opp(src_opp->np, i);
> +   if (!req_np)
> +   continue;
> +
> +   req_table = _find_table_of_opp_np(req_np);
Not yet tested in v4, but in v3:
In _find_table_of_opp_np(), there's a lockdep check:
lockdep_assert_held(_table_lock);
which would lead to lockdep warnings.

Call trace:
_find_table_of_opp_np
_of_lazy_link_required_tables
dev_pm_opp_xlate_opp


[PATCH] i2c: mediatek: disable zero-length transfers for mt8183

2019-07-26 Thread Hsin-Yi Wang
When doing i2cdetect quick write mode, we would get transfer
error ENOMEM, and i2cdetect shows there's no device at the address.
Quoting from mt8183 datasheet, the number of transfers to be
transferred in one transaction should be set to bigger than 1,
so we should forbid zero-length transfer and update functionality.

Incorrect return:
localhost ~ # i2cdetect -q -y 0
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:  -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

After this patch:
localhost ~ #  i2cdetect -q -y 0
Error: Can't use SMBus Quick Write command on this bus

localhost ~ #  i2cdetect -y 0
Warning: Can't use SMBus Quick Write command, will skip some addresses
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:
10:
20:
30: -- -- -- -- -- -- -- --
40:
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60:
70:

Reported-by: Alexandru M Stan 
Signed-off-by: Hsin-Yi Wang 
---
Previous patch and discussion:
http://patchwork.ozlabs.org/patch/1042684/
---
 drivers/i2c/busses/i2c-mt65xx.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c
index 252edb433fdf..2842ca4b8c3b 100644
--- a/drivers/i2c/busses/i2c-mt65xx.c
+++ b/drivers/i2c/busses/i2c-mt65xx.c
@@ -234,6 +234,10 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = 
{
.max_num_msgs = 255,
 };
 
+static const struct i2c_adapter_quirks mt8183_i2c_quirks = {
+   .flags = I2C_AQ_NO_ZERO_LEN,
+};
+
 static const struct mtk_i2c_compatible mt2712_compat = {
.regs = mt_i2c_regs_v1,
.pmic_i2c = 0,
@@ -298,6 +302,7 @@ static const struct mtk_i2c_compatible mt8173_compat = {
 };
 
 static const struct mtk_i2c_compatible mt8183_compat = {
+   .quirks = _i2c_quirks,
.regs = mt_i2c_regs_v2,
.pmic_i2c = 0,
.dcm = 0,
@@ -870,7 +875,11 @@ static irqreturn_t mtk_i2c_irq(int irqno, void *dev_id)
 
 static u32 mtk_i2c_functionality(struct i2c_adapter *adap)
 {
-   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+   if (adap->quirks->flags & I2C_AQ_NO_ZERO_LEN)
+   return I2C_FUNC_I2C |
+   (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
+   else
+   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
 static const struct i2c_algorithm mtk_i2c_algorithm = {
@@ -933,8 +942,8 @@ static int mtk_i2c_probe(struct platform_device *pdev)
i2c->dev = >dev;
i2c->adap.dev.parent = >dev;
i2c->adap.owner = THIS_MODULE;
-   i2c->adap.algo = _i2c_algorithm;
i2c->adap.quirks = i2c->dev_comp->quirks;
+   i2c->adap.algo = _i2c_algorithm;
i2c->adap.timeout = 2 * HZ;
i2c->adap.retries = 1;
 
-- 
2.20.1



Re: [PATCH RFC v2 0/2] Use cpu based scaling passive governor for MT8183 CCI

2019-07-18 Thread Hsin-Yi Wang
On Wed, Jul 17, 2019 at 2:12 PM Hsin-Yi Wang  wrote:
> 2. cpu based scaling support to passive_governor from Sibi Sankar
> https://lore.kernel.org/patchwork/patch/1101049/
This series is tested with previous version:
https://patchwork.kernel.org/patch/10875195/


[PATCH RFC v2 2/2] cpufreq: mediatek: Support vproc shared by multiple component

2019-07-17 Thread Hsin-Yi Wang
mt8183-cci shares vproc with small cluster. If the regulator is shared
between several devices then the lowest request voltage that meets the
system constraints will be used.

However, previous mediatek cpufreq implementation would cause race condition
if vproc is shared by multiple devices, which would crash device due to
incorrect voltage supply.

A race condition example:
cci sets vproc 90 --> vproc=90
cpu0 sets vproc 50 --> vproc=max(50,90)=90
cpu0 sets vproc 70 --> cpu0 reads vproc 90, target is lower, so decide to scale
   up frequency first, but before it set voltage...
cci sets vproc 60 --> vproc=max(60,50)=60. cpu0 already set freq to 70, but
  before it set voltage, vproc becomes 60, which is not
  sufficient for cpu0.

Let cpu and cci manages their own previous target voltage can avoid such race.

Signed-off-by: Hsin-Yi Wang 
---
 drivers/cpufreq/mediatek-cpufreq.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c 
b/drivers/cpufreq/mediatek-cpufreq.c
index 7282834e8fe2..f5e737b862f0 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -46,6 +46,7 @@ struct mtk_cpu_dvfs_info {
struct notifier_block opp_nb;
int opp_cpu;
unsigned long opp_freq;
+   int old_vproc;
 };
 
 static LIST_HEAD(dvfs_info_list);
@@ -196,11 +197,16 @@ static int mtk_cpufreq_voltage_tracking(struct 
mtk_cpu_dvfs_info *info,
 
 static int mtk_cpufreq_set_voltage(struct mtk_cpu_dvfs_info *info, int vproc)
 {
+   int ret;
+
if (info->need_voltage_tracking)
-   return mtk_cpufreq_voltage_tracking(info, vproc);
+   ret = mtk_cpufreq_voltage_tracking(info, vproc);
else
-   return regulator_set_voltage(info->proc_reg, vproc,
-vproc + VOLT_TOL);
+   ret = regulator_set_voltage(info->proc_reg, vproc,
+MAX_VOLT_LIMIT);
+   if (!ret)
+   info->old_vproc = vproc;
+   return ret;
 }
 
 static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
@@ -218,7 +224,9 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy 
*policy,
inter_vproc = info->intermediate_voltage;
 
old_freq_hz = clk_get_rate(cpu_clk);
-   old_vproc = regulator_get_voltage(info->proc_reg);
+   old_vproc = info->old_vproc;
+   if (old_vproc == 0)
+   old_vproc = regulator_get_voltage(info->proc_reg);
if (old_vproc < 0) {
pr_err("%s: invalid Vproc value: %d\n", __func__, old_vproc);
return old_vproc;
-- 
2.20.1



[PATCH RFC v2 0/2] Use cpu based scaling passive governor for MT8183 CCI

2019-07-17 Thread Hsin-Yi Wang
This series depends on following series:
1. mt8183 cpufreq and cci devfreq from andrew-sh.cheng
https://patchwork.kernel.org/cover/10946047/

2. cpu based scaling support to passive_governor from Sibi Sankar
https://lore.kernel.org/patchwork/patch/1101049/

This series uses cpu based scaling passive governor for mt8183-cci to improve
performance and deal with shared regulator voltage setting issue.

Hsin-Yi Wang (2):
  devfreq: mt8183-cci: using cpu based scaling passive_governor
  cpufreq: mediatek: Support vproc shared by multiple component

 drivers/cpufreq/mediatek-cpufreq.c   |  16 +-
 drivers/devfreq/mt8183-cci-devfreq.c | 239 +++
 2 files changed, 68 insertions(+), 187 deletions(-)

-- 
2.20.1



[PATCH RFC v2 1/2] devfreq: mt8183-cci: using cpu based scaling passive_governor

2019-07-17 Thread Hsin-Yi Wang
This is based on mediatek's devfreq patches[1].

In MT8183 SoC, CCI and little core cluster share same regulator. In original
implementation, CCI frequency depends on regulator voltage, which results in
bad memory access performance if tasks are loaded on other cpus other than
little cluster (cpus 0-3).

Using cpu based scaling devfreq passive governor can improve this situation,
since in most cases, higher cpufreq implies higher loadings on the CCI, and CCI
should consider all cpu loadings instead of only the little cluster.

[1] https://patchwork.kernel.org/patch/10946063/

Signed-off-by: Hsin-Yi Wang 
---
 drivers/devfreq/mt8183-cci-devfreq.c | 239 +++
 1 file changed, 56 insertions(+), 183 deletions(-)

diff --git a/drivers/devfreq/mt8183-cci-devfreq.c 
b/drivers/devfreq/mt8183-cci-devfreq.c
index 250c963789f3..4e8e5948ed41 100644
--- a/drivers/devfreq/mt8183-cci-devfreq.c
+++ b/drivers/devfreq/mt8183-cci-devfreq.c
@@ -11,189 +11,82 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "governor.h"
 
+#define MAX_VOLT_LIMIT (115)
+
 struct cci_devfreq {
struct devfreq *devfreq;
struct regulator *proc_reg;
-   unsigned long proc_reg_uV;
struct clk *cci_clk;
-   unsigned long freq;
-   struct notifier_block nb;
-   struct notifier_block opp_nb;
-   int cci_min_freq;
+   int old_vproc;
+   unsigned long old_freq;
 };
 
-static int cci_devfreq_regulator_notifier(struct notifier_block *nb,
- unsigned long val, void *data)
-{
-   int ret;
-   struct cci_devfreq *cci_df =
-   container_of(nb, struct cci_devfreq, nb);
-
-   /* deal with reduce frequency */
-   if (val & REGULATOR_EVENT_PRE_VOLTAGE_CHANGE) {
-   struct pre_voltage_change_data *pvc_data = data;
-
-   if (pvc_data->min_uV < pvc_data->old_uV) {
-   cci_df->proc_reg_uV =
-   (unsigned long)(pvc_data->min_uV);
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to reduce cci frequency: %d\n",
-  ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-   } else if ((val & REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE) &&
-   ((unsigned long)data > cci_df->proc_reg_uV)) {
-   cci_df->proc_reg_uV = (unsigned long)data;
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to raise cci frequency back: %d\n", ret);
-   mutex_unlock(_df->devfreq->lock);
-   } else if ((val & REGULATOR_EVENT_VOLTAGE_CHANGE) &&
-   (cci_df->proc_reg_uV < (unsigned long)data)) {
-   /* deal with increase frequency */
-   cci_df->proc_reg_uV = (unsigned long)data;
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to raise cci frequency: %d\n", ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-
-   return 0;
-}
-
-static int ccidevfreq_opp_notifier(struct notifier_block *nb,
-unsigned long event, void *data)
-{
-   int ret;
-   struct dev_pm_opp *opp = data;
-   struct cci_devfreq *cci_df = container_of(nb, struct cci_devfreq,
- opp_nb);
-   unsigned long   freq, volt, cur_volt;
-
-   if (event == OPP_EVENT_ADJUST_VOLTAGE) {
-   freq = dev_pm_opp_get_freq(opp);
-   /* current opp item is changed */
-   if (freq == cci_df->freq) {
-   volt = dev_pm_opp_get_voltage(opp);
-   cur_volt = regulator_get_voltage(cci_df->proc_reg);
-
-   if (volt > cur_volt) {
-   /* need reduce freq */
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to reduce cci frequency by 
opp notification: %d\n",
-  ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-   }
-
-   if (freq == cci_df->cci_min_freq) {
-   volt = dev_pm_opp_get_voltage(opp);
-   regulator_set_voltage(cci_df->proc_reg, volt, INT_MAX);
-   }
-   } else if (event == OPP_EVEN

Re: [PATCH RFC 2/9] OPP: Export a number of helpers to prevent code duplication

2019-07-07 Thread Hsin-Yi Wang
On Thu, Mar 28, 2019 at 3:28 PM Sibi Sankar  wrote:

> +
> +/* The caller must call dev_pm_opp_put() after the OPP is used */
> +struct dev_pm_opp *dev_pm_opp_find_opp_of_np(struct opp_table *opp_table,
> +struct device_node *opp_np)
> +{
> +   return _find_opp_of_np(opp_table, opp_np);
> +}
Hi Sibi,

Though this is not the latest version, we've seen following issue:

We would get lockdep warnings on this:
[   79.068957] Call trace:
[   79.071396]  _find_opp_of_np+0xa0/0xa8
[   79.075136]  dev_pm_opp_find_opp_of_np+0x24/0x30
[   79.079744]  devfreq_passive_event_handler+0x304/0x51c
[   79.084872]  devfreq_add_device+0x368/0x434
[   79.089046]  devm_devfreq_add_device+0x68/0xb0
[   79.093480]  mtk_cci_devfreq_probe+0x108/0x158
[   79.097915]  platform_drv_probe+0x80/0xb0
[   79.101915]  really_probe+0x1b4/0x28c
[   79.105568]  driver_probe_device+0x64/0xfc
[   79.109655]  __driver_attach+0x94/0xcc
[   79.113395]  bus_for_each_dev+0x84/0xcc
[   79.117221]  driver_attach+0x2c/0x38
[   79.120788]  bus_add_driver+0x120/0x1f4
[   79.124614]  driver_register+0x64/0xf8
[   79.128355]  __platform_driver_register+0x4c/0x58
[   79.133049]  mtk_cci_devfreq_init+0x1c/0x24
[   79.137224]  do_one_initcall+0x1c0/0x3e0
[   79.141138]  do_initcall_level+0x1f4/0x224
[   79.145225]  do_basic_setup+0x34/0x4c
[   79.148878]  kernel_init_freeable+0x10c/0x194
[   79.153225]  kernel_init+0x14/0x100
[   79.156705]  ret_from_fork+0x10/0x18
[   79.160270] irq event stamp: 238006
[   79.163750] hardirqs last  enabled at (238005):
[] _raw_spin_unlock_irqrestore+0x40/0x84
[   79.173391] hardirqs last disabled at (238006):
[] do_debug_exception+0x70/0x198
[   79.182337] softirqs last  enabled at (237998):
[] __do_softirq+0x45c/0x4a4
[   79.190850] softirqs last disabled at (237987):
[] irq_exit+0xd8/0xf8
[   79.198842] ---[ end trace 0e66a55077a0abab ]---

In _find_opp_of_np()[1], there's
lockdep_assert_held(_table_lock);

[1] https://elixir.bootlin.com/linux/latest/source/drivers/opp/of.c#L75

But in governor passive.c#cpufreq_passive_register(), it call
dev_pm_opp_find_opp_of_np() directly, so it wouldn't access
opp_table_lock lock.

Another similar place is in dev_pm_opp_of_add_table(), most devfreq
would call this to get opp table.
dev_pm_opp_of_add_table
 -->   _opp_add_static_v2
-->_of_opp_alloc_required_opps  // would goes here if opp
table contains "required-opps" property.
-->_find_opp_of_np
cpufreq-map governor needs devfreq to have "required-opps" property.
So it would also trigger above lockdep warning.


The question is: Is lockdep_assert_held(_table_lock); needed in
above use cases? Since they don't need to modify device and opp lists.

Thanks


[PATCH v7 3/3] arm64: kexec_file: add rng-seed support

2019-07-02 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
change log v6->v7:
* Use stack for rng_seed to avoid allocation failing.
---
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index 58871333737a..81b5baad97aa 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,19 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   u8 rng_seed[RNG_SEED_SIZE];
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   if (ret)
+   goto out;
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +125,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH v7 2/3] fdt: add support for rng-seed

2019-07-02 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Rob Herring 
---
No change since v6.
---
 drivers/of/fdt.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index cd17dc62a719..7be50e287ba6 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1043,6 +1044,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1077,6 +1079,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_device_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
-- 
2.20.1



[PATCH v7 0/3] add support for rng-seed

2019-07-02 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. This can be used for adding sufficient initial entropy
for stack canary. Especially architectures that lack per-stack canary.

Hsin-Yi Wang (3):
  arm64: map FDT as RW for early_init_dt_scan()
  fdt: add support for rng-seed
  arm64: kexec_file: add rng-seed support

 arch/arm64/include/asm/mmu.h   |  2 +-
 arch/arm64/kernel/kaslr.c  |  5 +
 arch/arm64/kernel/machine_kexec_file.c | 18 +-
 arch/arm64/kernel/setup.c  |  9 -
 arch/arm64/mm/mmu.c| 15 +--
 drivers/of/fdt.c   | 10 ++
 6 files changed, 38 insertions(+), 21 deletions(-)

-- 
2.20.1



[PATCH v7 1/3] arm64: map FDT as RW for early_init_dt_scan()

2019-07-02 Thread Hsin-Yi Wang
Currently in arm64, FDT is mapped to RO before it's passed to
early_init_dt_scan(). However, there might be some codes
(eg. commit "fdt: add support for rng-seed") that need to modify FDT
during init. Map FDT to RO after early fixups are done.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
Reviewed-by: Mike Rapoport 
---
No change since v5.
---
 arch/arm64/include/asm/mmu.h |  2 +-
 arch/arm64/kernel/kaslr.c|  5 +
 arch/arm64/kernel/setup.c|  9 -
 arch/arm64/mm/mmu.c  | 15 +--
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h
index fd6161336653..f217e3292919 100644
--- a/arch/arm64/include/asm/mmu.h
+++ b/arch/arm64/include/asm/mmu.h
@@ -126,7 +126,7 @@ extern void init_mem_pgprot(void);
 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
   unsigned long virt, phys_addr_t size,
   pgprot_t prot, bool page_mappings_only);
-extern void *fixmap_remap_fdt(phys_addr_t dt_phys);
+extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
 extern void mark_linear_text_alias_ro(void);
 
 #define INIT_MM_CONTEXT(name)  \
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 708051655ad9..d94a3e41cef9 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -62,9 +62,6 @@ static __init const u8 *kaslr_get_cmdline(void *fdt)
return default_cmdline;
 }
 
-extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
-  pgprot_t prot);
-
 /*
  * This routine will be executed with the kernel mapped at its default virtual
  * address, and if it returns successfully, the kernel will be remapped, and
@@ -93,7 +90,7 @@ u64 __init kaslr_early_init(u64 dt_phys)
 * attempt at mapping the FDT in setup_machine()
 */
early_fixmap_init();
-   fdt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
+   fdt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
if (!fdt)
return 0;
 
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 7e541f947b4c..754763b3fe28 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -170,9 +170,13 @@ static void __init smp_build_mpidr_hash(void)
 
 static void __init setup_machine_fdt(phys_addr_t dt_phys)
 {
-   void *dt_virt = fixmap_remap_fdt(dt_phys);
+   int size;
+   void *dt_virt = fixmap_remap_fdt(dt_phys, , PAGE_KERNEL);
const char *name;
 
+   if (dt_virt)
+   memblock_reserve(dt_phys, size);
+
if (!dt_virt || !early_init_dt_scan(dt_virt)) {
pr_crit("\n"
"Error: invalid device tree blob at physical address 
%pa (virtual address 0x%p)\n"
@@ -184,6 +188,9 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
cpu_relax();
}
 
+   /* Early fixups are done, map the FDT as read-only now */
+   fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
+
name = of_flat_dt_get_machine_name();
if (!name)
return;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 750a69dde39b..54e93583085c 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -876,7 +876,7 @@ void __set_fixmap(enum fixed_addresses idx,
}
 }
 
-void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
+void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 {
const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
int offset;
@@ -929,19 +929,6 @@ void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
-{
-   void *dt_virt;
-   int size;
-
-   dt_virt = __fixmap_remap_fdt(dt_phys, , PAGE_KERNEL_RO);
-   if (!dt_virt)
-   return NULL;
-
-   memblock_reserve(dt_phys, size);
-   return dt_virt;
-}
-
 int __init arch_ioremap_p4d_supported(void)
 {
return 0;
-- 
2.20.1



Re: [PATCH v6 3/3] arm64: kexec_file: add rng-seed support

2019-06-30 Thread Hsin-Yi Wang
On Fri, Jun 28, 2019 at 7:47 PM Hsin-Yi Wang  wrote:

> >
> > If the RNG wasn't initialised, we'd carry on with a warning. Why do we
> > follow a different policy here?
> >
(Sorry, please ignore previous comment)
I think this part should be same as kaslr, since they are both adding
random seeds:
If RNG isn't initialized, we won't be able to set these seeds, and dtb
can't do anything else to deal with this, so carry on with warning.
If fdt_setprop failed with no space, create_dtb() will try to setup
dtb again with more space.
Other failures are setting fdt's error, so returns invalid.


Re: [PATCH v6 3/3] arm64: kexec_file: add rng-seed support

2019-06-28 Thread Hsin-Yi Wang
On Fri, Jun 28, 2019 at 5:42 PM Mark Rutland  wrote:
>
> On Wed, Jun 12, 2019 at 12:33:02PM +0800, Hsin-Yi Wang wrote:
> > Adding "rng-seed" to dtb. It's fine to add this property if original
> > fdt doesn't contain it. Since original seed will be wiped after
> > read, so use a default size 128 bytes here.
>
> Why is 128 bytes the default value?
More than 64 bytes should be enough.
>
> I didn't see an update to Documentation/devicetree/bindings/chosen.txt,
> so it's not clear to me precisely what we expect.
>
Rob suggested to update in a newer dt-schema documentation at
https://github.com/devicetree-org/dt-schema.
A pull request has been sent but perhaps it would continue if kernel
patches are accepted.
>
> For 128 bytes, it would be better to use a buffer on the stack. That
> avoids the possibility of the allocation failing.
>
Okay, I'll update this.
>
> If the RNG wasn't initialised, we'd carry on with a warning. Why do we
> follow a different policy here?
>
For failure case, I think kernel can still be boot since this is not a
very fatal case, just same as the seed wasn't provided by bootloader
at first boot. So I'll also let fdt_setprop() failed case carry on
with warning.

Thanks


Re: [PATCH v6 2/3] fdt: add support for rng-seed

2019-06-28 Thread Hsin-Yi Wang
On Fri, Jun 28, 2019 at 5:35 PM Mark Rutland  wrote:
>
> On Wed, Jun 12, 2019 at 12:33:00PM +0800, Hsin-Yi Wang wrote:
> > Introducing a chosen node, rng-seed, which is an entropy that can be
> > passed to kernel called very early to increase initial device
> > randomness. Bootloader should provide this entropy and the value is
> > read from /chosen/rng-seed in DT.
>
> Could you please elaborate on this?
>
> * What is this initial entropy used by, and why is this important? I
>   assume that devices which can populate this will have a HW RNG that
>   the kernel will eventually make use of.
There are a few discussions here[0]. We basically want to add more
randomness for stack canary when device just boot and not much device
randomness was added.
[0] https://lore.kernel.org/patchwork/patch/1070974/#1268553

On Thu, May 9, 2019 at 1:00 AM Hsin-Yi Wang  wrote:
> This early added entropy is also going to be used for stack canary. At
> the time it's created there's not be much entropy (before
> boot_init_stack_canary(), there's only add_latent_entropy() and
> command_line).
> On arm64, there is a single canary for all tasks. If RNG is weak or
> the seed can be read, it might be easier to figure out the canary.

With newer compilers[1] there will be a per-task canary on arm64[2],
which will improve this situation, but many architectures lack a
per-task canary, unfortunately. I've also recently rearranged the RNG
initialization[3] which should also help with better entropy mixing.
But each of these are kind of band-aids against not having sufficient
initial entropy, which leaves the canary potentially exposed.

-Kees

[1] 
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=359c1bf35e3109d2f3882980b47a5eae46123259
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0a1213fa7432778b71a1c0166bf56660a3aab030
[3] 
https://git.kernel.org/pub/scm/linux/kernel/git/tytso/random.git/commit/?h=dev=d55535232c3dbde9a523a9d10d68670f5fe5dec3
>
> * How much entropy is necessary or sufficient?
64 bytes should be enough. But depends on how much bootloader can provide.
>
> * Why is the DT the right mechanism for this?
EFI based systems can inject randomness in early boot. This is aimed
to support DT based systems to also have this feature.

https://github.com/torvalds/linux/commit/636259880a7e7d3446a707dddebc799da94bdd0b#diff-3ded2fe21b37c6f3e86c2a8418507714

Thanks


Re: [PATCH RFC 1/2] PM / devfreq: Generic CPU frequency to device frequency mapping governor

2019-06-20 Thread Hsin-Yi Wang
Thanks!

On Thu, Jun 20, 2019 at 5:41 PM Sibi Sankar  wrote:
>
> Hey Hsin-Yi, Chanwoo
>
> On 2019-06-20 15:02, Hsin-Yi Wang wrote:
> > Hi Chanwoo Choi, Saravana Kannan and Sibi Sankar,
> >
> > I've also tested Sibi Sankar's patch[1] locally with mt8183-cci, and
> > it works fine too!
> > It'd be great if Sibi Sankar or anyone who is familiar with the
> > original design can finish this implementation. But if no one has time
> > to do that, I think I can also help on address the comments. Thanks!
>
> Now that we have a user :) I am happy
> to repost the patch with the comments
> addressed.
>
> https://lkml.org/lkml/2019/6/14/4
> Also with ^^ patch and few more in the
> series the dt parsing of required-opps
> should get further simplified.
>
> >
> >
> > [1]
> > [RFC,2/9] OPP: Export a number of helpers to prevent code duplication
> > - https://patchwork.kernel.org/patch/10875199/
> > [RFC,3/9] PM / devfreq: Add cpu based scaling support to
> > passive_governor
> > - https://patchwork.kernel.org/patch/10875195/
> >
> > Hsin-Yi
> >
> > On Thu, Jun 20, 2019 at 2:56 PM Chanwoo Choi 
> > wrote:
> >>
> >> + Sibi Sankar
> >>
> >> Hi, Hsin-Yi Wang, Saravana Kannan and Sibi Sankar
> >>
> >> I summarized the history of the related patch about this title.
> >>
> >> Firstly,
> >> As I knew, Saravana sent the patch[1] which contains
> >> 'governor_cpufreq_map.c' last year. According to the Myungoo's
> >> comment,
> >>
> >> Secondly,
> >> Sibi Sankar modified the 'governor_passive.c'[2] in order to support
> >> the mapping between cpu frequency and device frequency.
> >> Unfortunately, Sibi Sankar stopped the development about this
> >> because he had found the other method to get his purpose as I knew.
> >>
> >> Thirdly,
> >> Hsin-Yi Wang send the original patch of Saravana without modification.
> >>
> >>
> >> Sincerely, I think that the mapping between cpu frequency and device
> >> frequency is necessary. And I prefer the Sibi's approach which
> >> implements
> >> stuff to the existing 'passive' governor.
> >>
> >> We need to discuss about how to implement them by whom.
> >>
> >>
> >> [1] [v3,1/2] PM / devfreq: Generic CPU frequency to device frequency
> >> mapping governor
> >> - https://patchwork.kernel.org/patch/10553171/
> >>
> >> [2]
> >> [PATCH RFC 0/9] Add CPU based scaling support to Passive governor
> >> -
> >> https://lore.kernel.org/lkml/08c3cff8c39e3d82e044db93e992d...@codeaurora.org/T/
> >> [PATCH RFC 3/9] PM / devfreq: Add cpu based scaling support to
> >> passive_governor
> >> -
> >> https://lore.kernel.org/lkml/08c3cff8c39e3d82e044db93e992d...@codeaurora.org/T/#m1cafb7baf687d2a680d39c85d3ec7d1b590b68fc
> >>
> >>
> >> Best Regards,
> >> Chanwoo Choi
> >>
> >> On 19. 6. 18. 오후 1:14, Hsin-Yi Wang wrote:
> >> > From: Saravana Kannan 
> >> >
> >> > From: Saravana Kannan 
> >> >
> >> > Many CPU architectures have caches that can scale independent of the 
> >> > CPUs.
> >> > Frequency scaling of the caches is necessary to make sure the cache is 
> >> > not
> >> > a performance bottleneck that leads to poor performance and power. The 
> >> > same
> >> > idea applies for RAM/DDR.
> >> >
> >> > To achieve this, this patch adds a generic devfreq governor that takes 
> >> > the
> >> > current frequency of each CPU frequency domain and then adjusts the
> >> > frequency of the cache (or any devfreq device) based on the frequency of
> >> > the CPUs. It listens to CPU frequency transition notifiers to keep itself
> >> > up to date on the current CPU frequency.
> >> >
> >> > To decide the frequency of the device, the governor does one of the
> >> > following:
> >> >
> >> > * Uses a CPU frequency to device frequency mapping table
> >> >   - Either one mapping table used for all CPU freq policies (typically 
> >> > used
> >> > for system with homogeneous cores/clusters that have the same OPPs).
> >> >   - One mapping table per CPU freq policy (typically used for ASMP 
> >> > systems
> >> > with heterogeneous CPUs with different OPPs)
> >> >
> >> > OR
> >

Re: [PATCH RFC 1/2] PM / devfreq: Generic CPU frequency to device frequency mapping governor

2019-06-20 Thread Hsin-Yi Wang
Hi Chanwoo Choi, Saravana Kannan and Sibi Sankar,

I've also tested Sibi Sankar's patch[1] locally with mt8183-cci, and
it works fine too!
It'd be great if Sibi Sankar or anyone who is familiar with the
original design can finish this implementation. But if no one has time
to do that, I think I can also help on address the comments. Thanks!


[1]
[RFC,2/9] OPP: Export a number of helpers to prevent code duplication
- https://patchwork.kernel.org/patch/10875199/
[RFC,3/9] PM / devfreq: Add cpu based scaling support to passive_governor
- https://patchwork.kernel.org/patch/10875195/

Hsin-Yi

On Thu, Jun 20, 2019 at 2:56 PM Chanwoo Choi  wrote:
>
> + Sibi Sankar
>
> Hi, Hsin-Yi Wang, Saravana Kannan and Sibi Sankar
>
> I summarized the history of the related patch about this title.
>
> Firstly,
> As I knew, Saravana sent the patch[1] which contains
> 'governor_cpufreq_map.c' last year. According to the Myungoo's comment,
>
> Secondly,
> Sibi Sankar modified the 'governor_passive.c'[2] in order to support
> the mapping between cpu frequency and device frequency.
> Unfortunately, Sibi Sankar stopped the development about this
> because he had found the other method to get his purpose as I knew.
>
> Thirdly,
> Hsin-Yi Wang send the original patch of Saravana without modification.
>
>
> Sincerely, I think that the mapping between cpu frequency and device
> frequency is necessary. And I prefer the Sibi's approach which implements
> stuff to the existing 'passive' governor.
>
> We need to discuss about how to implement them by whom.
>
>
> [1] [v3,1/2] PM / devfreq: Generic CPU frequency to device frequency mapping 
> governor
> - https://patchwork.kernel.org/patch/10553171/
>
> [2]
> [PATCH RFC 0/9] Add CPU based scaling support to Passive governor
> - 
> https://lore.kernel.org/lkml/08c3cff8c39e3d82e044db93e992d...@codeaurora.org/T/
> [PATCH RFC 3/9] PM / devfreq: Add cpu based scaling support to 
> passive_governor
> - 
> https://lore.kernel.org/lkml/08c3cff8c39e3d82e044db93e992d...@codeaurora.org/T/#m1cafb7baf687d2a680d39c85d3ec7d1b590b68fc
>
>
> Best Regards,
> Chanwoo Choi
>
> On 19. 6. 18. 오후 1:14, Hsin-Yi Wang wrote:
> > From: Saravana Kannan 
> >
> > From: Saravana Kannan 
> >
> > Many CPU architectures have caches that can scale independent of the CPUs.
> > Frequency scaling of the caches is necessary to make sure the cache is not
> > a performance bottleneck that leads to poor performance and power. The same
> > idea applies for RAM/DDR.
> >
> > To achieve this, this patch adds a generic devfreq governor that takes the
> > current frequency of each CPU frequency domain and then adjusts the
> > frequency of the cache (or any devfreq device) based on the frequency of
> > the CPUs. It listens to CPU frequency transition notifiers to keep itself
> > up to date on the current CPU frequency.
> >
> > To decide the frequency of the device, the governor does one of the
> > following:
> >
> > * Uses a CPU frequency to device frequency mapping table
> >   - Either one mapping table used for all CPU freq policies (typically used
> > for system with homogeneous cores/clusters that have the same OPPs).
> >   - One mapping table per CPU freq policy (typically used for ASMP systems
> > with heterogeneous CPUs with different OPPs)
> >
> > OR
> >
> > * Scales the device frequency in proportion to the CPU frequency. So, if
> >   the CPUs are running at their max frequency, the device runs at its max
> >   frequency.  If the CPUs are running at their min frequency, the device
> >   runs at its min frequency. And interpolated for frequencies in between.
> >
> > Signed-off-by: Saravana Kannan 
> > Signed-off-by: Hsin-Yi Wang 
> > ---
> >  .../bindings/devfreq/devfreq-cpufreq-map.txt  |  53 ++
> >  drivers/devfreq/Kconfig   |   8 +
> >  drivers/devfreq/Makefile  |   1 +
> >  drivers/devfreq/governor_cpufreq_map.c| 583 ++
> >  4 files changed, 645 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
> >  create mode 100644 drivers/devfreq/governor_cpufreq_map.c
> >
> > diff --git 
> > a/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt 
> > b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
> > new file mode 100644
> > index ..982a30bcfc86
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
> > @@ -0,0 +1,53 @@
> > +Devfreq CPUfreq governor
> > +
> > +devfreq-c

[PATCH RFC 1/2] PM / devfreq: Generic CPU frequency to device frequency mapping governor

2019-06-17 Thread Hsin-Yi Wang
From: Saravana Kannan 

From: Saravana Kannan 

Many CPU architectures have caches that can scale independent of the CPUs.
Frequency scaling of the caches is necessary to make sure the cache is not
a performance bottleneck that leads to poor performance and power. The same
idea applies for RAM/DDR.

To achieve this, this patch adds a generic devfreq governor that takes the
current frequency of each CPU frequency domain and then adjusts the
frequency of the cache (or any devfreq device) based on the frequency of
the CPUs. It listens to CPU frequency transition notifiers to keep itself
up to date on the current CPU frequency.

To decide the frequency of the device, the governor does one of the
following:

* Uses a CPU frequency to device frequency mapping table
  - Either one mapping table used for all CPU freq policies (typically used
for system with homogeneous cores/clusters that have the same OPPs).
  - One mapping table per CPU freq policy (typically used for ASMP systems
with heterogeneous CPUs with different OPPs)

OR

* Scales the device frequency in proportion to the CPU frequency. So, if
  the CPUs are running at their max frequency, the device runs at its max
  frequency.  If the CPUs are running at their min frequency, the device
  runs at its min frequency. And interpolated for frequencies in between.

Signed-off-by: Saravana Kannan 
Signed-off-by: Hsin-Yi Wang 
---
 .../bindings/devfreq/devfreq-cpufreq-map.txt  |  53 ++
 drivers/devfreq/Kconfig   |   8 +
 drivers/devfreq/Makefile  |   1 +
 drivers/devfreq/governor_cpufreq_map.c| 583 ++
 4 files changed, 645 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
 create mode 100644 drivers/devfreq/governor_cpufreq_map.c

diff --git a/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt 
b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
new file mode 100644
index ..982a30bcfc86
--- /dev/null
+++ b/Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
@@ -0,0 +1,53 @@
+Devfreq CPUfreq governor
+
+devfreq-cpufreq-map is a parent device that contains one or more child devices.
+Each child device provides CPU frequency to device frequency mapping for a
+specific device. Examples of devices that could use this are: DDR, cache and
+CCI.
+
+Parent device name shall be "devfreq-cpufreq-map".
+
+Required child device properties:
+- cpu-to-dev-map, or cpu-to-dev-map-:
+   A list of tuples where each tuple consists of a
+   CPU frequency (KHz) and the corresponding device
+   frequency. CPU frequencies not listed in the table
+   will use the device frequency that corresponds to the
+   next rounded up CPU frequency.
+   Use "cpu-to-dev-map" if all CPUs in the system should
+   share same mapping.
+   Use cpu-to-dev-map- to describe different
+   mappings for different CPUs. The property should be
+   listed only for the first CPU if multiple CPUs are
+   synchronous.
+- target-dev:  Phandle to device that this mapping applies to.
+
+Example:
+   devfreq-cpufreq-map {
+   cpubw-cpufreq {
+   target-dev = <>;
+   cpu-to-dev-map =
+   <  30  1144000 >,
+   <  422400  2288000 >,
+   <  652800  3051000 >,
+   <  883200  5996000 >,
+   < 1190400  8056000 >,
+   < 1497600 10101000 >,
+   < 1728000 12145000 >,
+   < 2649600 1625 >;
+   };
+
+   cache-cpufreq {
+   target-dev = <>;
+   cpu-to-dev-map =
+   <  30  30 >,
+   <  422400  422400 >,
+   <  652800  499200 >,
+   <  883200  576000 >,
+   <  96  96 >,
+   < 1497600 1036800 >,
+   < 1574400 1574400 >,
+   < 1728000 1651200 >,
+   < 2649600 1728000 >;
+   };
+   };
diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
index 0c8204d6b78a..0303f5a400b6 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -74,6 +74,14 @@ config DEVFREQ_GOV_PASSIVE
  through sysfs entries. The passive governor recommends that
  devfreq de

[PATCH RFC 2/2] devfreq: mt8183-cci: using cpufreq-map governor in cci dvfs driver

2019-06-17 Thread Hsin-Yi Wang
From: Hsin-Yi Wang 

This is based on mediatek's devfreq patches[1].

In MT8183 SoC, CCI and little core cluster share same regulator. In original
implementation, CCI frequency depends on regulator voltage, which results in
bad memory access performance if tasks are loaded on other cpus other than
little cluster (cpus 0-3).

Using cpufreq-map mt8183-cci's devfreq governor can improve this situation,
since in most cases, higher cpufreq implies higher loadings on the CCI, and CCI
should consider all cpu loadings instead of only the little cluster.

[1] https://patchwork.kernel.org/patch/10946063/

Signed-off-by: Hsin-Yi Wang 
---
 drivers/devfreq/mt8183-cci-devfreq.c | 194 +--
 1 file changed, 4 insertions(+), 190 deletions(-)

diff --git a/drivers/devfreq/mt8183-cci-devfreq.c 
b/drivers/devfreq/mt8183-cci-devfreq.c
index 250c963789f3..a153adee033e 100644
--- a/drivers/devfreq/mt8183-cci-devfreq.c
+++ b/drivers/devfreq/mt8183-cci-devfreq.c
@@ -17,164 +17,7 @@
 struct cci_devfreq {
struct devfreq *devfreq;
struct regulator *proc_reg;
-   unsigned long proc_reg_uV;
struct clk *cci_clk;
-   unsigned long freq;
-   struct notifier_block nb;
-   struct notifier_block opp_nb;
-   int cci_min_freq;
-};
-
-static int cci_devfreq_regulator_notifier(struct notifier_block *nb,
- unsigned long val, void *data)
-{
-   int ret;
-   struct cci_devfreq *cci_df =
-   container_of(nb, struct cci_devfreq, nb);
-
-   /* deal with reduce frequency */
-   if (val & REGULATOR_EVENT_PRE_VOLTAGE_CHANGE) {
-   struct pre_voltage_change_data *pvc_data = data;
-
-   if (pvc_data->min_uV < pvc_data->old_uV) {
-   cci_df->proc_reg_uV =
-   (unsigned long)(pvc_data->min_uV);
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to reduce cci frequency: %d\n",
-  ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-   } else if ((val & REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE) &&
-   ((unsigned long)data > cci_df->proc_reg_uV)) {
-   cci_df->proc_reg_uV = (unsigned long)data;
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to raise cci frequency back: %d\n", ret);
-   mutex_unlock(_df->devfreq->lock);
-   } else if ((val & REGULATOR_EVENT_VOLTAGE_CHANGE) &&
-   (cci_df->proc_reg_uV < (unsigned long)data)) {
-   /* deal with increase frequency */
-   cci_df->proc_reg_uV = (unsigned long)data;
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to raise cci frequency: %d\n", ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-
-   return 0;
-}
-
-static int ccidevfreq_opp_notifier(struct notifier_block *nb,
-unsigned long event, void *data)
-{
-   int ret;
-   struct dev_pm_opp *opp = data;
-   struct cci_devfreq *cci_df = container_of(nb, struct cci_devfreq,
- opp_nb);
-   unsigned long   freq, volt, cur_volt;
-
-   if (event == OPP_EVENT_ADJUST_VOLTAGE) {
-   freq = dev_pm_opp_get_freq(opp);
-   /* current opp item is changed */
-   if (freq == cci_df->freq) {
-   volt = dev_pm_opp_get_voltage(opp);
-   cur_volt = regulator_get_voltage(cci_df->proc_reg);
-
-   if (volt > cur_volt) {
-   /* need reduce freq */
-   mutex_lock(_df->devfreq->lock);
-   ret = update_devfreq(cci_df->devfreq);
-   if (ret)
-   pr_err("Fail to reduce cci frequency by 
opp notification: %d\n",
-  ret);
-   mutex_unlock(_df->devfreq->lock);
-   }
-   }
-
-   if (freq == cci_df->cci_min_freq) {
-   volt = dev_pm_opp_get_voltage(opp);
-   regulator_set_voltage(cci_df->proc_reg, volt, INT_MAX);
-   }
-   } else if (event == OPP_EVENT_DISABLE) {
-   }
-
-   return 0;
-}
-
-
-static int mtk_cci_governor_get_target(struct devfreq *devfreq,
-  unsigned long *fr

[PATCH RFC 0/2] Use cpufreq-map governor for MT8183 CCI

2019-06-17 Thread Hsin-Yi Wang
From: Hsin-Yi Wang 

This series uses cpufreq-map governor for mt8183-cci to improve performance.

Hsin-Yi Wang (1):
  devfreq: mt8183-cci: using cpufreq-map governor in cci dvfs driver

Saravana Kannan (1):
  PM / devfreq: Generic CPU frequency to device frequency mapping
governor

 .../bindings/devfreq/devfreq-cpufreq-map.txt  |  53 ++
 drivers/devfreq/Kconfig   |   8 +
 drivers/devfreq/Makefile  |   1 +
 drivers/devfreq/governor_cpufreq_map.c| 583 ++
 drivers/devfreq/mt8183-cci-devfreq.c  | 194 +-
 5 files changed, 649 insertions(+), 190 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/devfreq/devfreq-cpufreq-map.txt
 create mode 100644 drivers/devfreq/governor_cpufreq_map.c

-- 
2.20.1



[PATCH v6 3/3] arm64: kexec_file: add rng-seed support

2019-06-11 Thread Hsin-Yi Wang
Adding "rng-seed" to dtb. It's fine to add this property if original
fdt doesn't contain it. Since original seed will be wiped after
read, so use a default size 128 bytes here.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
change log v5->v6:
* no change
---
 arch/arm64/kernel/machine_kexec_file.c | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index 58871333737a..d40fde72a023 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -27,6 +27,8 @@
 #define FDT_PROP_INITRD_END"linux,initrd-end"
 #define FDT_PROP_BOOTARGS  "bootargs"
 #define FDT_PROP_KASLR_SEED"kaslr-seed"
+#define FDT_PROP_RNG_SEED  "rng-seed"
+#define RNG_SEED_SIZE  128
 
 const struct kexec_file_ops * const kexec_file_loaders[] = {
_image_ops,
@@ -102,6 +104,23 @@ static int setup_dtb(struct kimage *image,
FDT_PROP_KASLR_SEED);
}
 
+   /* add rng-seed */
+   if (rng_is_initialized()) {
+   void *rng_seed = kmalloc(RNG_SEED_SIZE, GFP_ATOMIC);
+   get_random_bytes(rng_seed, RNG_SEED_SIZE);
+
+   ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed,
+   RNG_SEED_SIZE);
+   kfree(rng_seed);
+
+   if (ret)
+   goto out;
+
+   } else {
+   pr_notice("RNG is not initialised: omitting \"%s\" property\n",
+   FDT_PROP_RNG_SEED);
+   }
+
 out:
if (ret)
return (ret == -FDT_ERR_NOSPACE) ? -ENOMEM : -EINVAL;
@@ -110,7 +129,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs and kaslr-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed, and
+ * rng-seed.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
-- 
2.20.1



[PATCH v6 2/3] fdt: add support for rng-seed

2019-06-11 Thread Hsin-Yi Wang
Introducing a chosen node, rng-seed, which is an entropy that can be
passed to kernel called very early to increase initial device
randomness. Bootloader should provide this entropy and the value is
read from /chosen/rng-seed in DT.

Signed-off-by: Hsin-Yi Wang 
Reviewed-by: Stephen Boyd 
---
change log v5->v6:
* remove Documentation change
---
 drivers/of/fdt.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 3d36b5afd9bd..369130dbd42c 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1052,6 +1053,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 {
int l;
const char *p;
+   const void *rng_seed;
 
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
 
@@ -1086,6 +1088,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
pr_debug("Command line is: %s\n", (char*)data);
 
+   rng_seed = of_get_flat_dt_prop(node, "rng-seed", );
+   if (rng_seed && l > 0) {
+   add_device_randomness(rng_seed, l);
+
+   /* try to clear seed so it won't be found. */
+   fdt_nop_property(initial_boot_params, node, "rng-seed");
+   }
+
/* break now */
return 1;
 }
-- 
2.20.1



<    1   2   3   4   >