]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'remotes/karo-tx53/karo-tx53' into karo-tx-linux
authorLothar Waßmann <LW@KARO-electronics.de>
Tue, 24 Oct 2017 13:19:46 +0000 (15:19 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Tue, 24 Oct 2017 13:19:46 +0000 (15:19 +0200)
Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt
arch/arm/boot/dts/imx28-tx28.dts
drivers/net/ethernet/freescale/fec.h
drivers/net/ethernet/freescale/fec_main.c
drivers/video/backlight/pwm_bl.c

index 764db86d441ad131aceca0e15146d5c914d97919..95594c341a571e68ec4dbe5885be8ad81342af64 100644 (file)
@@ -17,6 +17,10 @@ Optional properties:
                "pwms" property (see PWM binding[0])
   - enable-gpios: contains a single GPIO specifier for the GPIO which enables
                   and disables the backlight (see GPIO binding[1])
+  - turn-on-delay-ms: delay in milliseconds between configuring the PWM
+                 and switching PWM on. This may be required to eliminate
+                 flicker when switching the PWM on after it has been
+                 disabled.
 
 [0]: Documentation/devicetree/bindings/pwm/pwm.txt
 [1]: Documentation/devicetree/bindings/gpio/gpio.txt
index 0ebbc83852d026fbdd9684424b62a7a9d10720ea..222368f4be575f4f6f9e9a0bdaca0c673cb5e9e9 100644 (file)
@@ -1,13 +1,43 @@
 /*
  * Copyright 2012 Shawn Guo <shawn.guo@linaro.org>
- * Copyright 2013 Lothar Waßmann <LW@KARO-electronics.de>
+ * Copyright 2013-2017 Lothar Waßmann <LW@KARO-electronics.de>
  *
- * The code contained herein is licensed under the GNU General Public
- * License. You may obtain a copy of the GNU General Public License
- * Version 2 at the following locations:
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
  *
- * http://www.opensource.org/licenses/gpl-license.html
- * http://www.gnu.org/copyleft/gpl.html
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License
+ *     version 2 as published by the Free Software Foundation.
+ *
+ *     This file is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /dts-v1/;
                status = "disabled";
        };
 
-       regulators {
-               compatible = "simple-bus";
-               #address-cells = <1>;
-               #size-cells = <0>;
-
-               reg_usb0_vbus: regulator@0 {
-                       compatible = "regulator-fixed";
-                       reg = <0>;
-                       regulator-name = "usb0_vbus";
-                       regulator-min-microvolt = <5000000>;
-                       regulator-max-microvolt = <5000000>;
-                       gpio = <&gpio0 18 GPIO_ACTIVE_HIGH>;
-                       enable-active-high;
-               };
+       reg_usb0_vbus: regulator-usb0-vbus {
+               compatible = "regulator-fixed";
+               regulator-name = "usb0_vbus";
+               regulator-min-microvolt = <5000000>;
+               regulator-max-microvolt = <5000000>;
+               gpio = <&gpio0 18 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
 
-               reg_usb1_vbus: regulator@1 {
-                       compatible = "regulator-fixed";
-                       reg = <1>;
-                       regulator-name = "usb1_vbus";
-                       regulator-min-microvolt = <5000000>;
-                       regulator-max-microvolt = <5000000>;
-                       gpio = <&gpio3 27 GPIO_ACTIVE_HIGH>;
-                       enable-active-high;
-               };
+       reg_usb1_vbus: regulator-usb1-vbus {
+               compatible = "regulator-fixed";
+               regulator-name = "usb1_vbus";
+               regulator-min-microvolt = <5000000>;
+               regulator-max-microvolt = <5000000>;
+               gpio = <&gpio3 27 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
 
-               reg_2p5v: regulator@2 {
-                       compatible = "regulator-fixed";
-                       reg = <2>;
-                       regulator-name = "2P5V";
-                       regulator-min-microvolt = <2500000>;
-                       regulator-max-microvolt = <2500000>;
-                       regulator-always-on;
-               };
+       reg_2p5v: regulator-2p5v {
+               compatible = "regulator-fixed";
+               regulator-name = "2P5V";
+               regulator-min-microvolt = <2500000>;
+               regulator-max-microvolt = <2500000>;
+               regulator-always-on;
+       };
 
-               reg_3p3v: regulator@3 {
-                       compatible = "regulator-fixed";
-                       reg = <3>;
-                       regulator-name = "3P3V";
-                       regulator-min-microvolt = <3300000>;
-                       regulator-max-microvolt = <3300000>;
-                       regulator-always-on;
-               };
+       reg_3p3v: regulator-3p3v {
+               compatible = "regulator-fixed";
+               regulator-name = "3P3V";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               regulator-always-on;
+       };
 
-               reg_can_xcvr: regulator@4 {
-                       compatible = "regulator-fixed";
-                       reg = <4>;
-                       regulator-name = "CAN XCVR";
-                       regulator-min-microvolt = <3300000>;
-                       regulator-max-microvolt = <3300000>;
-                       gpio = <&gpio1 0 GPIO_ACTIVE_HIGH>;
-                       pinctrl-names = "default";
-                       pinctrl-0 = <&tx28_flexcan_xcvr_pins>;
-               };
+       reg_can_xcvr: regulator-can-xcvr {
+               compatible = "regulator-fixed";
+               regulator-name = "CAN XCVR";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               gpio = <&gpio1 0 GPIO_ACTIVE_HIGH>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&tx28_flexcan_xcvr_pins>;
+       };
 
-               reg_lcd: regulator@5 {
-                       compatible = "regulator-fixed";
-                       reg = <5>;
-                       regulator-name = "LCD POWER";
-                       regulator-min-microvolt = <3300000>;
-                       regulator-max-microvolt = <3300000>;
-                       gpio = <&gpio1 31 GPIO_ACTIVE_HIGH>;
-                       enable-active-high;
-               };
+       reg_lcd: regulator-lcd-power {
+               compatible = "regulator-fixed";
+               regulator-name = "LCD POWER";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               gpio = <&gpio1 31 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
 
-               reg_lcd_reset: regulator@6 {
-                       compatible = "regulator-fixed";
-                       reg = <6>;
-                       regulator-name = "LCD RESET";
-                       regulator-min-microvolt = <3300000>;
-                       regulator-max-microvolt = <3300000>;
-                       gpio = <&gpio3 30 GPIO_ACTIVE_HIGH>;
-                       startup-delay-us = <300000>;
-                       enable-active-high;
-                       regulator-always-on;
-                       regulator-boot-on;
-               };
+       reg_lcd_reset: regulator-lcd-reset {
+               compatible = "regulator-fixed";
+               regulator-name = "LCD RESET";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               gpio = <&gpio3 30 GPIO_ACTIVE_HIGH>;
+               startup-delay-us = <300000>;
+               enable-active-high;
+               regulator-always-on;
+               regulator-boot-on;
        };
 
        clocks {
                pinctrl-names = "default";
                pinctrl-0 = <&tx28_pca9554_pins>;
                interrupt-parent = <&gpio3>;
-               interrupts = <28 0>;
+               interrupts = <28 IRQ_TYPE_NONE>;
                gpio-controller;
                #gpio-cells = <2>;
                interrupt-controller;
                pinctrl-names = "default";
                pinctrl-0 = <&tx28_tsc2007_pins>;
                interrupt-parent = <&gpio3>;
-               interrupts = <20 0>;
+               interrupts = <20 IRQ_TYPE_EDGE_FALLING>;
                pendown-gpio = <&gpio3 20 GPIO_ACTIVE_LOW>;
                ti,x-plate-ohms = /bits/ 16 <660>;
        };
        ds1339: rtc@68 {
                compatible = "mxim,ds1339";
                reg = <0x68>;
+               trickle-resistor-ohms = <250>;
+               trickle-diode-disable;
        };
 };
 
index 38c7b21e5d63faaeae25ad45715aecb5a3469578..4c2de04fe0aa87f46d7e4c065fa9530e8787bb43 100644 (file)
@@ -523,6 +523,11 @@ struct fec_enet_private {
 
        int     dev_id;
 
+       int     reset_gpio;
+       int     phy_reset_duration;
+       int     phy_post_delay;
+       int     reset_active_high;
+
        /* Phylib and MDIO interface */
        struct  mii_bus *mii_bus;
        int     mii_timeout;
index a6e323f1563745c3a0cedd91d240e05af6606f33..3c2cff8677044f7a8c2a51be1abca09c7f8d441b 100644 (file)
@@ -1836,6 +1836,8 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
        return ret;
 }
 
+static void fec_reset_phy(struct fec_enet_private *fep);
+
 static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
 {
        struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1846,9 +1848,13 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
                if (ret)
                        return ret;
 
-               ret = clk_prepare_enable(fep->clk_enet_out);
-               if (ret)
-                       goto failed_clk_enet_out;
+               if (fep->clk_enet_out) {
+                       ret = clk_prepare_enable(fep->clk_enet_out);
+                       if (ret)
+                               goto failed_clk_enet_out;
+
+                       fec_reset_phy(fep);
+               }
 
                if (fep->clk_ptp) {
                        mutex_lock(&fep->ptp_clk_mutex);
@@ -3213,67 +3219,90 @@ static int fec_enet_init(struct net_device *ndev)
 }
 
 #ifdef CONFIG_OF
-static int fec_reset_phy(struct platform_device *pdev)
+static void fec_reset_phy(struct fec_enet_private *fep)
 {
-       int err, phy_reset;
-       bool active_high = false;
-       int msec = 1, phy_post_delay = 0;
-       struct device_node *np = pdev->dev.of_node;
+       if (!gpio_is_valid(fep->reset_gpio))
+               return;
 
-       if (!np)
-               return 0;
+       gpio_set_value_cansleep(fep->reset_gpio, fep->reset_active_high);
 
-       err = of_property_read_u32(np, "phy-reset-duration", &msec);
-       /* A sane reset duration should not be longer than 1s */
-       if (!err && msec > 1000)
-               msec = 1;
+       if (fep->phy_reset_duration > 20)
+               msleep(fep->phy_reset_duration);
+       else
+               usleep_range(fep->phy_reset_duration * 1000,
+                            fep->phy_reset_duration * 1000 + 1000);
 
-       phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
-       if (phy_reset == -EPROBE_DEFER)
-               return phy_reset;
-       else if (!gpio_is_valid(phy_reset))
-               return 0;
+       gpio_set_value_cansleep(fep->reset_gpio, !fep->reset_active_high);
 
-       err = of_property_read_u32(np, "phy-reset-post-delay", &phy_post_delay);
-       /* valid reset duration should be less than 1s */
-       if (!err && phy_post_delay > 1000)
-               return -EINVAL;
+       if (!fep->phy_post_delay)
+               return;
+       if (fep->phy_post_delay > 20)
+               msleep(fep->phy_post_delay);
+       else
+               usleep_range(fep->phy_post_delay * 1000,
+                            fep->phy_post_delay * 1000 + 1000);
+}
 
-       active_high = of_property_read_bool(np, "phy-reset-active-high");
+static int fec_get_reset_gpio(struct platform_device *pdev)
+{
+       int err;
+       struct device_node *np = pdev->dev.of_node;
+       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct fec_enet_private *fep = netdev_priv(ndev);
+
+       /* Most DT files do not specify the correct polarity
+        * of the phy-reset GPIO.
+        * So use this special property to signal the actual
+        * signal polarity.
+        */
+       fep->reset_gpio = of_get_named_gpio(np, "phy-reset-gpios", 0);
+       if (fep->reset_gpio == -EPROBE_DEFER)
+               return -EPROBE_DEFER;
+       if (!gpio_is_valid(fep->reset_gpio))
+               return 0;
 
-       err = devm_gpio_request_one(&pdev->dev, phy_reset,
-                       active_high ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
-                       "phy-reset");
+       fep->reset_active_high = of_property_read_bool(np,
+                                                      "phy-reset-active-high");
+
+       err = devm_gpio_request_one(&pdev->dev, fep->reset_gpio,
+                                   fep->reset_active_high ?
+                                   GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
+                                   "phy-reset");
        if (err) {
                dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
                return err;
        }
 
-       if (msec > 20)
-               msleep(msec);
-       else
-               usleep_range(msec * 1000, msec * 1000 + 1000);
-
-       gpio_set_value_cansleep(phy_reset, !active_high);
-
-       if (!phy_post_delay)
-               return 0;
+       err = of_property_read_u32(np, "phy-reset-duration",
+                                  &fep->phy_reset_duration);
+       /* A sane reset duration should not be longer than 1s */
+       if (err || fep->phy_reset_duration > 1000)
+               fep->phy_reset_duration = 1;
 
-       if (phy_post_delay > 20)
-               msleep(phy_post_delay);
-       else
-               usleep_range(phy_post_delay * 1000,
-                            phy_post_delay * 1000 + 1000);
+       err = of_property_read_u32(np, "phy-reset-post-delay",
+                                  &fep->phy_post_delay);
+       /* valid post reset delay should be less than 1s */
+       if (err)
+               fep->phy_post_delay = 0;
+       else if (fep->phy_post_delay > 1000)
+               return -EINVAL;
 
        return 0;
 }
 #else /* CONFIG_OF */
-static int fec_reset_phy(struct platform_device *pdev)
+/* In case of platform probe, the reset has been done
+ * by machine code.
+ */
+static inline void fec_reset_phy(struct fec_enet_private *fep)
 {
-       /*
-        * In case of platform probe, the reset has been done
-        * by machine code.
-        */
+}
+
+static int fec_get_reset_gpio(struct platform_device *pdev)
+{
+       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct fec_enet_private *fep = netdev_priv(ndev);
+
+       fep->reset_gpio = -EINVAL;
        return 0;
 }
 #endif /* CONFIG_OF */
@@ -3294,19 +3323,16 @@ fec_enet_get_queue_num(struct platform_device *pdev, int *num_tx, int *num_rx)
        of_property_read_u32(np, "fsl,num-rx-queues", num_rx);
 
        if (*num_tx < 1 || *num_tx > FEC_ENET_MAX_TX_QS) {
-               dev_warn(&pdev->dev, "Invalid num_tx(=%d), fall back to 1\n",
+               dev_warn(&pdev->dev, "Invalid fsl,num-tx-queues value %d; fall back to 1\n",
                         *num_tx);
                *num_tx = 1;
-               return;
        }
 
        if (*num_rx < 1 || *num_rx > FEC_ENET_MAX_RX_QS) {
-               dev_warn(&pdev->dev, "Invalid num_rx(=%d), fall back to 1\n",
+               dev_warn(&pdev->dev, "Invalid fsl,num-rx-queues value %d; fall back to 1\n",
                         *num_rx);
                *num_rx = 1;
-               return;
        }
-
 }
 
 static int
@@ -3458,9 +3484,10 @@ fec_probe(struct platform_device *pdev)
        pm_runtime_set_active(&pdev->dev);
        pm_runtime_enable(&pdev->dev);
 
-       ret = fec_reset_phy(pdev);
+       ret = fec_get_reset_gpio(pdev);
        if (ret)
                goto failed_reset;
+       fec_reset_phy(fep);
 
        if (fep->bufdesc_ex)
                fec_ptp_init(pdev);
index 002f1ce22bd02032062924b19d645ebc25302c93..9578f6516c65a5b0d88e1c163c4053e0cfa0366e 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/pwm_backlight.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 
 struct pwm_bl_data {
        struct pwm_device       *pwm;
@@ -35,6 +36,7 @@ struct pwm_bl_data {
        struct gpio_desc        *enable_gpio;
        unsigned int            scale;
        bool                    legacy;
+       int                     turn_on_delay_ms;
        int                     (*notify)(struct device *,
                                          int brightness);
        void                    (*notify_after)(struct device *,
@@ -50,6 +52,19 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
        if (pb->enabled)
                return;
 
+       pwm_enable(pb->pwm);
+
+       if (pb->turn_on_delay_ms > 0) {
+               dev_dbg(pb->dev, "Sleeping %u..%uµs\n",
+                       pb->turn_on_delay_ms * 1000,
+                       pb->turn_on_delay_ms * 1100);
+               if (pb->turn_on_delay_ms > 20)
+                       msleep(pb->turn_on_delay_ms);
+               else
+                       usleep_range(pb->turn_on_delay_ms * 1000,
+                            pb->turn_on_delay_ms * 1100);
+       }
+
        err = regulator_enable(pb->power_supply);
        if (err < 0)
                dev_err(pb->dev, "failed to enable power supply\n");
@@ -57,7 +72,6 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
        if (pb->enable_gpio)
                gpiod_set_value_cansleep(pb->enable_gpio, 1);
 
-       pwm_enable(pb->pwm);
        pb->enabled = true;
 }
 
@@ -107,8 +121,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
                duty_cycle = compute_duty_cycle(pb, brightness);
                pwm_config(pb->pwm, duty_cycle, pb->period);
                pwm_backlight_power_on(pb, brightness);
-       } else
+       } else {
                pwm_backlight_power_off(pb);
+       }
 
        if (pb->notify_after)
                pb->notify_after(pb->dev, brightness);
@@ -263,9 +278,9 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                                pb->scale = data->levels[i];
 
                pb->levels = data->levels;
-       } else
+       } else {
                pb->scale = data->max_brightness;
-
+       }
        pb->notify = data->notify;
        pb->notify_after = data->notify_after;
        pb->check_fb = data->check_fb;
@@ -328,6 +343,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                goto err_alloc;
        }
 
+       of_property_read_u32(node, "turn-on-delay-ms", &pb->turn_on_delay_ms);
+
        dev_dbg(&pdev->dev, "got pwm for backlight\n");
 
        /*