4554 lines
122 KiB
Diff
Executable file
4554 lines
122 KiB
Diff
Executable file
diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/Makefile linux/arch/arm64/boot/dts/rockchip/Makefile
|
|
--- linux.orig/arch/arm64/boot/dts/rockchip/Makefile 2022-11-01 17:55:23.658604366 -0400
|
|
+++ linux/arch/arm64/boot/dts/rockchip/Makefile 2022-11-01 17:56:17.128793891 -0400
|
|
@@ -43,6 +43,7 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-na
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-orangepi.dtb
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-pinebook-pro.dtb
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-puma-haikou.dtb
|
|
+dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-rg552-linux.dtb
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-roc-pc.dtb
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-roc-pc-mezzanine.dtb
|
|
dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-roc-pc-plus.dtb
|
|
diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3399-opp.dtsi linux/arch/arm64/boot/dts/rockchip/rk3399-opp.dtsi
|
|
--- linux.orig/arch/arm64/boot/dts/rockchip/rk3399-opp.dtsi 2022-11-01 17:55:23.662604223 -0400
|
|
+++ linux/arch/arm64/boot/dts/rockchip/rk3399-opp.dtsi 2022-11-01 17:56:17.128793891 -0400
|
|
@@ -101,6 +101,10 @@
|
|
opp-hz = /bits/ 64 <800000000>;
|
|
opp-microvolt = <1100000 1100000 1150000>;
|
|
};
|
|
+ opp06 {
|
|
+ opp-hz = /bits/ 64 <900000000>;
|
|
+ opp-microvolt = <1100000 1100000 1150000>;
|
|
+ };
|
|
};
|
|
};
|
|
|
|
diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3399-rg552-linux.dts linux/arch/arm64/boot/dts/rockchip/rk3399-rg552-linux.dts
|
|
--- linux.orig/arch/arm64/boot/dts/rockchip/rk3399-rg552-linux.dts 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/arch/arm64/boot/dts/rockchip/rk3399-rg552-linux.dts 2022-11-01 17:56:17.132793763 -0400
|
|
@@ -0,0 +1,1407 @@
|
|
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
|
+/*
|
|
+ * Copyright (c) 2017 Fuzhou Rockchip Electronics Co., Ltd.
|
|
+ * Copyright (c) 2018 Akash Gajjar <Akash_Gajjar@mentor.com>
|
|
+ * Copyright (c) 2022 Maya Matuszczyk <maccraft123mc@gmail.com>
|
|
+ */
|
|
+
|
|
+
|
|
+/dts-v1/;
|
|
+#include <dt-bindings/input/linux-event-codes.h>
|
|
+#include <dt-bindings/pwm/pwm.h>
|
|
+#include <dt-bindings/usb/pd.h>
|
|
+#include "rk3399.dtsi"
|
|
+#include "rk3399-opp.dtsi"
|
|
+
|
|
+/ {
|
|
+ model = "Anbernic RG552";
|
|
+ compatible = "anbernic,rg552", "rockchip,rk3399";
|
|
+
|
|
+ aliases {
|
|
+ mmc0 = &sdio0;
|
|
+ mmc1 = &sdmmc;
|
|
+ mmc2 = &sdhci;
|
|
+ };
|
|
+
|
|
+ chosen {
|
|
+ stdout-path = "serial2:1500000n8";
|
|
+ };
|
|
+
|
|
+ memory {
|
|
+ device_type = "memory";
|
|
+ reg = <0x0 0x00200000 0x0 0xf7e00000>;
|
|
+ };
|
|
+
|
|
+ volume-keys {
|
|
+ compatible = "gpio-keys";
|
|
+ autorepeat;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vol_pwr_btn>;
|
|
+
|
|
+ sw1 {
|
|
+ debounce-interval = <100>;
|
|
+ gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_LOW>;
|
|
+ label = "BTN PWR";
|
|
+ linux,code = <KEY_POWER>;
|
|
+ wakeup-source;
|
|
+ };
|
|
+ sw2 {
|
|
+ label = "BTN VOL+";
|
|
+ linux,code = <KEY_VOLUMEUP>;
|
|
+ gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_LOW>;
|
|
+ };
|
|
+ sw3 {
|
|
+ label = "BTN VOL-";
|
|
+ linux,code = <KEY_VOLUMEDOWN>;
|
|
+ gpios = <&gpio3 RK_PB6 GPIO_ACTIVE_LOW>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ adc-keys {
|
|
+ compatible = "adc-keys";
|
|
+ io-channels = <&saradc 1>;
|
|
+ io-channel-names = "buttons";
|
|
+ keyup-threshold-microvolt = <1800000>;
|
|
+ poll-interval = <100>;
|
|
+
|
|
+ home-key {
|
|
+ linux,code = <BTN_MODE>;
|
|
+ label = "F Button";
|
|
+ press-threshold-microvolt = <1750>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ joypad: singleadc-joypad {
|
|
+ compatible = "singleadc-joypad";
|
|
+
|
|
+ pwms = <&pwm3 0 200000000 0>;
|
|
+ pwm-names = "enable";
|
|
+ rumble-boost-weak = <0x0000>;
|
|
+ rumble-boost-strong = <0x0000>;
|
|
+
|
|
+ joypad-name = "retrogame_joypad";
|
|
+ joypad-product = <0x1101>;
|
|
+ joypad-revision = <0x0100>;
|
|
+
|
|
+ status = "okay";
|
|
+
|
|
+ /* gpio pincontrol setup */
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&btn_pins>;
|
|
+
|
|
+ /* Analog mux define */
|
|
+ io-channel-names = "amux_adc";
|
|
+ io-channels = <&saradc 4>;
|
|
+
|
|
+ /* adc mux channel count */
|
|
+ amux-count = <4>;
|
|
+ /* adc mux select(a,b) gpio */
|
|
+ amux-a-gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_LOW>;
|
|
+ amux-b-gpios = <&gpio1 RK_PA0 GPIO_ACTIVE_LOW>;
|
|
+ /* adc mux enable gpio */
|
|
+ amux-en-gpios = <&gpio1 RK_PA4 GPIO_ACTIVE_LOW>;
|
|
+
|
|
+ /* adc calculate scale */
|
|
+ button-adc-scale = <2>;
|
|
+
|
|
+ /* adc deadzone range */
|
|
+ button-adc-deadzone = <64>;
|
|
+
|
|
+ /*
|
|
+ specifies fuzz value that is used to filter noise from
|
|
+ the event stream.
|
|
+ */
|
|
+ button-adc-fuzz = <32>;
|
|
+ button-adc-flat = <32>;
|
|
+
|
|
+ /*
|
|
+ Analog Stick data tuning value(precent)
|
|
+ p = positive direction, n = negative direction
|
|
+ report value = (real_adc_data * tuning_value) / 100
|
|
+ */
|
|
+ abs_x-p-tuning = <300>;
|
|
+ abs_x-n-tuning = <300>;
|
|
+
|
|
+ abs_y-p-tuning = <300>;
|
|
+ abs_y-n-tuning = <300>;
|
|
+
|
|
+ abs_rx-p-tuning = <300>;
|
|
+ abs_rx-n-tuning = <300>;
|
|
+
|
|
+ abs_ry-p-tuning = <300>;
|
|
+ abs_ry-n-tuning = <300>;
|
|
+
|
|
+ /* poll device interval (ms), adc read interval */
|
|
+ poll-interval = <10>;
|
|
+
|
|
+ /* required for RG552(invert) */
|
|
+ invert-absx;
|
|
+ invert-absy;
|
|
+
|
|
+ /* gpio button auto repeat set value : default disable */
|
|
+ /*
|
|
+ autorepeat;
|
|
+ */
|
|
+ sw1 {
|
|
+ gpios = <&gpio3 RK_PA0 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO DPAD-UP";
|
|
+ linux,code = <BTN_DPAD_UP>;
|
|
+ };
|
|
+ sw2 {
|
|
+ gpios = <&gpio3 RK_PA1 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO DPAD-DOWN";
|
|
+ linux,code = <BTN_DPAD_DOWN>;
|
|
+ };
|
|
+ sw3 {
|
|
+ gpios = <&gpio3 RK_PA3 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO DPAD-LEFT";
|
|
+ linux,code = <BTN_DPAD_LEFT>;
|
|
+ };
|
|
+ sw4 {
|
|
+ gpios = <&gpio3 RK_PA2 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO DPAD-RIGHT";
|
|
+ linux,code = <BTN_DPAD_RIGHT>;
|
|
+ };
|
|
+ sw5 {
|
|
+ gpios = <&gpio3 RK_PA6 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO KEY BTN-A";
|
|
+ linux,code = <BTN_EAST>;
|
|
+ };
|
|
+ sw6 {
|
|
+ gpios = <&gpio3 RK_PA7 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN-B";
|
|
+ linux,code = <BTN_SOUTH>;
|
|
+ };
|
|
+ sw7 {
|
|
+ gpios = <&gpio3 RK_PA4 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN-X";
|
|
+ linux,code = <BTN_NORTH>;
|
|
+ };
|
|
+ sw8 {
|
|
+ gpios = <&gpio3 RK_PA5 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN-Y";
|
|
+ linux,code = <BTN_WEST>;
|
|
+ };
|
|
+ sw9 {
|
|
+ gpios = <&gpio3 RK_PB1 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_SELECT";
|
|
+ linux,code = <BTN_SELECT>;
|
|
+ };
|
|
+ sw10 {
|
|
+ gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_START";
|
|
+ linux,code = <BTN_START>;
|
|
+ };
|
|
+ sw11 {
|
|
+ gpios = <&gpio3 RK_PC0 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_F";
|
|
+ linux,code = <BTN_MODE>;
|
|
+ };
|
|
+ sw12 {
|
|
+ gpios = <&gpio3 RK_PD0 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_TL";
|
|
+ linux,code = <BTN_TL>;
|
|
+ };
|
|
+ sw13 {
|
|
+ gpios = <&gpio3 RK_PD2 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_TR";
|
|
+ linux,code = <BTN_TR>;
|
|
+ };
|
|
+ sw14 {
|
|
+ gpios = <&gpio3 RK_PD1 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_TL2";
|
|
+ linux,code = <BTN_TL2>;
|
|
+ };
|
|
+ sw15 {
|
|
+ gpios = <&gpio3 RK_PD3 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_TR2";
|
|
+ linux,code = <BTN_TR2>;
|
|
+ };
|
|
+ sw16 {
|
|
+ gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_THUMBL";
|
|
+ linux,code = <BTN_THUMBL>;
|
|
+ };
|
|
+ sw17 {
|
|
+ gpios = <&gpio3 RK_PB4 GPIO_ACTIVE_LOW>;
|
|
+ label = "GPIO BTN_THUMBR";
|
|
+ linux,code = <BTN_THUMBR>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ leds: gpio-leds {
|
|
+ compatible = "gpio-leds";
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 =<&leds_gpio>;
|
|
+
|
|
+ led@1 {
|
|
+ gpios = <&gpio1 RK_PC4 GPIO_ACTIVE_HIGH>;
|
|
+ label = "battery_green";
|
|
+ default-state= "on";
|
|
+ // retain-state-suspended;
|
|
+ };
|
|
+
|
|
+ led@2 {
|
|
+ gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_HIGH>;
|
|
+ label = "battery_red";
|
|
+ // retain-state-suspended;
|
|
+ };
|
|
+
|
|
+ };
|
|
+
|
|
+ es8316-sound {
|
|
+ compatible = "simple-audio-card";
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&hp_det_pin>;
|
|
+ simple-audio-card,name = "rockchip,es8316-codec";
|
|
+ simple-audio-card,format = "i2s";
|
|
+ simple-audio-card,mclk-fs = <256>;
|
|
+
|
|
+ simple-audio-card,widgets =
|
|
+ "Headphone", "Headphones",
|
|
+ "Speaker", "Speaker";
|
|
+ simple-audio-card,routing =
|
|
+ "Headphones", "HPOL",
|
|
+ "Headphones", "HPOR",
|
|
+ "Speaker Amplifier INL", "HPOL",
|
|
+ "Speaker Amplifier INR", "HPOR",
|
|
+ "Speaker", "Speaker Amplifier OUTL",
|
|
+ "Speaker", "Speaker Amplifier OUTR";
|
|
+
|
|
+ simple-audio-card,hp-det-gpio = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
|
|
+ simple-audio-card,aux-devs = <&speaker_amp>;
|
|
+ simple-audio-card,pin-switches = "Speaker";
|
|
+
|
|
+ simple-audio-card,cpu {
|
|
+ sound-dai = <&i2s1>;
|
|
+ };
|
|
+
|
|
+ simple-audio-card,codec {
|
|
+ sound-dai = <&es8316>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ speaker_amp: speaker-amplifier {
|
|
+ compatible = "simple-audio-amplifier";
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&spk_en_pin>;
|
|
+ enable-gpios = <&gpio1 RK_PC5 GPIO_ACTIVE_HIGH>;
|
|
+ sound-name-prefix = "Speaker Amplifier";
|
|
+ VCC-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ fan: pwm-fan {
|
|
+ compatible = "pwm-fan";
|
|
+ pwms = <&pwm1 0 10000 1>;
|
|
+ #cooling-cells = <2>;
|
|
+ cooling-levels = <80 140 200 255>;
|
|
+ fan-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ backlight: backlight {
|
|
+ status = "okay";
|
|
+ compatible = "pwm-backlight";
|
|
+ pwms = <&pwm0 0 25000 0>;
|
|
+ //power-supply = <&vcc12v_dcin>;
|
|
+ brightness-levels = <
|
|
+ 0 1 2 3 4 5 6 7
|
|
+ 8 9 10 11 12 13 14 15
|
|
+ 16 17 18 19 20 21 22 23
|
|
+ 24 25 26 27 28 29 30 31
|
|
+ 32 33 34 35 36 37 38 39
|
|
+ 40 41 42 43 44 45 46 47
|
|
+ 48 49 50 51 52 53 54 55
|
|
+ 56 57 58 59 60 61 62 63
|
|
+ 64 65 66 67 68 69 70 71
|
|
+ 72 73 74 75 76 77 78 79
|
|
+ 80 81 82 83 84 85 86 87
|
|
+ 88 89 90 91 92 93 94 95
|
|
+ 96 97 98 99 100 101 102 103
|
|
+ 104 105 106 107 108 109 110 111
|
|
+ 112 113 114 115 116 117 118 119
|
|
+ 120 121 122 123 124 125 126 127
|
|
+ 128 129 130 131 132 133 134 135
|
|
+ 136 137 138 139 140 141 142 143
|
|
+ 144 145 146 147 148 149 150 151
|
|
+ 152 153 154 155 156 157 158 159
|
|
+ 160 161 162 163 164 165 166 167
|
|
+ 168 169 170 171 172 173 174 175
|
|
+ 176 177 178 179 180 181 182 183
|
|
+ 184 185 186 187 188 189 190 191
|
|
+ 192 193 194 195 196 197 198 199
|
|
+ 200 201 202 203 204 205 206 207
|
|
+ 208 209 210 211 212 213 214 215
|
|
+ 216 217 218 219 220 221 222 223
|
|
+ 224 225 226 227 228 229 230 231
|
|
+ 232 233 234 235 236 237 238 239
|
|
+ 240 241 242 243 244 245 246 247
|
|
+ 248 249 250 251 252 253 254 255>;
|
|
+ default-brightness-level = <200>;
|
|
+ };
|
|
+ bat: battery {
|
|
+ compatible = "simple-battery";
|
|
+ charge-full-design-microamp-hours = <6400000>;
|
|
+ voltage-max-design-microvolt = <4350000>;
|
|
+ voltage-min-design-microvolt = <3400000>;
|
|
+ constant-charge-current-max-microamp = <1500000>;
|
|
+ constant-charge-voltage-max-microvolt = <4350000>;
|
|
+ factory-internal-resistance-micro-ohms = <150000>;
|
|
+ resistance-temp-table = <20 150>;
|
|
+
|
|
+ ocv-capacity-celsius = <20>;
|
|
+ ocv-capacity-table-0 = <4308000 100>,<4217000 95>,
|
|
+ <4161000 90>,<4110000 85>,
|
|
+ <4066000 80>,<4007000 75>,
|
|
+ <3974000 70>,<3937000 65>,
|
|
+ <3896000 60>,<3853000 55>,
|
|
+ <3827000 50>,<3807000 45>,
|
|
+ <3793000 40>,<3780000 35>,
|
|
+ <3768000 30>,<3756000 25>,
|
|
+ <3740000 20>,<3716000 15>,
|
|
+ <3689000 10>,<3675000 5>,
|
|
+ <3400000 0>;
|
|
+ };
|
|
+
|
|
+ mains_charger: dc-charger {
|
|
+ compatible = "gpio-charger";
|
|
+ charger-type = "mains";
|
|
+ gpios = <&gpio4 RK_PD0 GPIO_ACTIVE_LOW>;
|
|
+
|
|
+ /* Also triggered by USB charger */
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&dc_det_pin>;
|
|
+ monitored-battery = <&bat>;
|
|
+ };
|
|
+
|
|
+ xin32k: xin32k {
|
|
+ compatible = "fixed-clock";
|
|
+ clock-frequency = <32768>;
|
|
+ clock-output-names = "xin32k";
|
|
+ #clock-cells = <0>;
|
|
+ };
|
|
+
|
|
+ clkin_gmac: external-gmac-clock {
|
|
+ compatible = "fixed-clock";
|
|
+ clock-frequency = <125000000>;
|
|
+ clock-output-names = "clkin_gmac";
|
|
+ #clock-cells = <0>;
|
|
+ };
|
|
+
|
|
+ /* TODO: shouldn't be here */
|
|
+ vcc12v_dcin: vcc12v-dcin {
|
|
+ compatible = "regulator-fixed";
|
|
+ regulator-name = "vcc12v_dcin";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <12000000>;
|
|
+ regulator-max-microvolt = <12000000>;
|
|
+ };
|
|
+
|
|
+ vcc_sys: vcc-sys {
|
|
+ compatible = "regulator-fixed";
|
|
+ regulator-name = "vcc_sys";
|
|
+ regulator-min-microvolt = <5000000>;
|
|
+ regulator-max-microvolt = <5000000>;
|
|
+ regulator-always-on;
|
|
+ vin-supply = <&vcc12v_dcin>;
|
|
+ };
|
|
+
|
|
+ vcc3v3_sys: vcc3v3-sys {
|
|
+ compatible = "regulator-fixed";
|
|
+ regulator-name = "vcc3v3_sys";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <3300000>;
|
|
+ regulator-max-microvolt = <3300000>;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ vcc3v0_sd: vcc3v0-sd {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio0 RK_PA1 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&sdmmc0_pwr_h>;
|
|
+ regulator-name = "vcc3v0_sd";
|
|
+ regulator-always-on;
|
|
+ regulator-min-microvolt = <3000000>;
|
|
+ regulator-max-microvolt = <3000000>;
|
|
+ vin-supply = <&vcc3v3_sys>;
|
|
+
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc5v0_host: vcc5v0-host-regulator {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio4 RK_PD2 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vcc5v0_host_en>;
|
|
+ regulator-name = "vcc5v0_host";
|
|
+ regulator-always-on;
|
|
+ regulator-min-microvolt = <5000000>;
|
|
+ regulator-max-microvolt = <5000000>;
|
|
+ vin-supply = <&vcc5v0_usb>;
|
|
+ };
|
|
+
|
|
+ vcc5v0_typec: vcc5v0-typec-regulator {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vcc5v0_typec_en>;
|
|
+ regulator-name = "vcc5v0_typec";
|
|
+ regulator-always-on;
|
|
+ vin-supply = <&vcc5v0_usb>;
|
|
+ };
|
|
+
|
|
+ vcc5v0_sys: vcc5v0-sys {
|
|
+ compatible = "regulator-fixed";
|
|
+ regulator-name = "vcc5v0_sys";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <5000000>;
|
|
+ regulator-max-microvolt = <5000000>;
|
|
+ vin-supply = <&vcc12v_dcin>;
|
|
+ };
|
|
+
|
|
+ vcc5v0_usb: vcc5v0-usb {
|
|
+ compatible = "regulator-fixed";
|
|
+ regulator-name = "vcc5v0_usb";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <5000000>;
|
|
+ regulator-max-microvolt = <5000000>;
|
|
+ vin-supply = <&vcc12v_dcin>;
|
|
+ };
|
|
+
|
|
+ vdd_log: vdd-log {
|
|
+ compatible = "pwm-regulator";
|
|
+ pwms = <&pwm2 0 25000 1>;
|
|
+ regulator-name = "vdd_log";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <800000>;
|
|
+ regulator-max-microvolt = <1700000>;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ vcc5v5_lcd: vcc5v5-lcd {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio4 RK_PD3 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vcc5v5_lcd_en>;
|
|
+ regulator-name = "vcc5v5_lcd";
|
|
+ regulator-min-microvolt = <5500000>;
|
|
+ regulator-max-microvolt = <5500000>;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ vcc5v5_neg_lcd: vcc5v5-neg-lcd {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio4 RK_PD1 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vcc5v5_neg_lcd_en>;
|
|
+ regulator-name = "vcc5v5_neg_lcd";
|
|
+ /*
|
|
+ * technically negative
|
|
+ */
|
|
+ regulator-min-microvolt = <5500000>;
|
|
+ regulator-max-microvolt = <5500000>;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+ };
|
|
+
|
|
+ vcc_wifi: vcc-wifi-regulator {
|
|
+ compatible = "regulator-fixed";
|
|
+ enable-active-high;
|
|
+ gpio = <&gpio3 RK_PC1 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&wifi_pwr>;
|
|
+ regulator-name = "wifi_enable";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ };
|
|
+
|
|
+ dmc_opp_table: dmc_opp_table {
|
|
+ compatible = "operating-points-v2";
|
|
+
|
|
+ opp-300000000 {
|
|
+ opp-hz = /bits/ 64 <300000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ opp-666000000 {
|
|
+ opp-hz = /bits/ 64 <666000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ opp-800000000 {
|
|
+ opp-hz = /bits/ 64 <800000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ opp-856000000 {
|
|
+ opp-hz = /bits/ 64 <856000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ opp-928000000 {
|
|
+ opp-hz = /bits/ 64 <928000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ opp-933000000 {
|
|
+ opp-hz = /bits/ 64 <933000000>;
|
|
+ opp-microvolt = <900000>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&cluster0_opp {
|
|
+ opp-1512000000 {
|
|
+ opp-hz = /bits/ 64 <1512000000>;
|
|
+ opp-microvolt = <1200000>;
|
|
+ };
|
|
+ opp-1608000000 {
|
|
+ opp-hz = /bits/ 64 <1608000000>;
|
|
+ opp-microvolt = <1200000>;
|
|
+ };
|
|
+ opp-1704000000 {
|
|
+ opp-hz = /bits/ 64 <1704000000>;
|
|
+ opp-microvolt = <1225000>;
|
|
+ };
|
|
+};
|
|
+
|
|
+&cluster1_opp {
|
|
+ opp-1992000000 {
|
|
+ opp-hz = /bits/ 64 <1992000000>;
|
|
+ opp-microvolt = <1250000>;
|
|
+ };
|
|
+ opp-2016000000 {
|
|
+ opp-hz = /bits/ 64 <2016000000>;
|
|
+ opp-microvolt = <1250000>;
|
|
+ };
|
|
+ opp-2040000000 {
|
|
+ opp-hz = /bits/ 64 <2040000000>;
|
|
+ opp-microvolt = <1250000>;
|
|
+ };
|
|
+ opp-2088000000 {
|
|
+ opp-hz = /bits/ 64 <2088000000>;
|
|
+ opp-microvolt = <1250000>;
|
|
+ };
|
|
+ opp-2184000000 {
|
|
+ opp-hz = /bits/ 64 <2184000000>;
|
|
+ opp-microvolt = <1350000>;
|
|
+ };
|
|
+};
|
|
+
|
|
+&cpu_thermal {
|
|
+ trips {
|
|
+ cpu_warm: cpu_warm {
|
|
+ temperature = <50000>;
|
|
+ hysteresis = <2000>;
|
|
+ type = "active";
|
|
+ };
|
|
+
|
|
+ cpu_hot: cpu_hot {
|
|
+ temperature = <55000>;
|
|
+ hysteresis = <2000>;
|
|
+ type = "active";
|
|
+ };
|
|
+
|
|
+ cpu_scalding: cpu_scalding {
|
|
+ temperature = <65000>;
|
|
+ hysteresis = <5000>;
|
|
+ type = "active";
|
|
+ };
|
|
+ };
|
|
+
|
|
+ cooling-maps {
|
|
+ map1 {
|
|
+ trip = <&cpu_warm>;
|
|
+ cooling-device = <&fan THERMAL_NO_LIMIT 1>;
|
|
+ };
|
|
+
|
|
+ map2 {
|
|
+ trip = <&cpu_hot>;
|
|
+ cooling-device = <&fan THERMAL_NO_LIMIT 1>;
|
|
+ };
|
|
+
|
|
+ map3 {
|
|
+ trip = <&cpu_scalding>;
|
|
+ cooling-device = <&fan 2 THERMAL_NO_LIMIT>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&cpu_l0 {
|
|
+ cpu-supply = <&vdd_cpu_l>;
|
|
+};
|
|
+
|
|
+&cpu_l1 {
|
|
+ cpu-supply = <&vdd_cpu_l>;
|
|
+};
|
|
+
|
|
+&cpu_l2 {
|
|
+ cpu-supply = <&vdd_cpu_l>;
|
|
+};
|
|
+
|
|
+&cpu_l3 {
|
|
+ cpu-supply = <&vdd_cpu_l>;
|
|
+};
|
|
+
|
|
+&cpu_b0 {
|
|
+ cpu-supply = <&vdd_cpu_b>;
|
|
+};
|
|
+
|
|
+&cpu_b1 {
|
|
+ cpu-supply = <&vdd_cpu_b>;
|
|
+};
|
|
+
|
|
+&saradc {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&sdio0 {
|
|
+ clock-frequency = <150000000>;
|
|
+ clock-freq-min-max = <100000 150000000>;
|
|
+ supports-sd;
|
|
+ no-sdio;
|
|
+ bus-width = <4>;
|
|
+ disable-wp;
|
|
+ cap-sd-highspeed;
|
|
+ cap-sdio-irq;
|
|
+ keep-power-in-suspend;
|
|
+ card-detect-delay = <800>;
|
|
+ cd-gpios = <&gpio2 RK_PC1 GPIO_ACTIVE_LOW>; /*[> CD GPIO <]*/
|
|
+ num-slots = <1>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&sdio0_clk &sdio0_cmd &sdio0_cd &sdio0_bus4>;
|
|
+ sd-uhs-sdr104;
|
|
+ vqmmc-supply = <&vcc3v0_touch>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&sdmmc {
|
|
+ bus-width = <4>;
|
|
+ cap-sd-highspeed;
|
|
+ cd-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
|
|
+ disable-wp;
|
|
+ max-frequency = <150000000>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_bus4>;
|
|
+ vmmc-supply = <&vcc3v0_sd>;
|
|
+ vqmmc-supply = <&vcc_sdio>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&emmc_phy {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&gpu {
|
|
+ mali-supply = <&vdd_gpu>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&pwm0 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&pwm1 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&pwm2 {
|
|
+ status = "okay";
|
|
+ pinctrl-names = "active";
|
|
+ pinctrl-0 = <&pwm2_pin_pull_down>;
|
|
+};
|
|
+
|
|
+&pwm3 {
|
|
+ status = "okay";
|
|
+ label = "rumble-pwm";
|
|
+};
|
|
+
|
|
+&saradc {
|
|
+ vref-supply = <&vcc_1v8>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&sdhci {
|
|
+ assigned-clock-rates = <150000000>;
|
|
+
|
|
+ bus-width = <8>;
|
|
+ mmc-hs400-1_8v;
|
|
+ mmc-hs400-enhanced-strobe;
|
|
+ non-removable;
|
|
+
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&hdmi {
|
|
+ ddc-i2c-bus = <&i2c3>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&hdmi_cec>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&mipi_dsi {
|
|
+ status = "okay";
|
|
+ clock-master;
|
|
+
|
|
+ ports {
|
|
+ mipi_out: port@1 {
|
|
+ #address-cells = <0>;
|
|
+ #size-cells = <0>;
|
|
+ reg = <1>;
|
|
+
|
|
+ mipi_out_panel: endpoint {
|
|
+ remote-endpoint = <&mipi_in_panel>;
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+
|
|
+ panel@0 {
|
|
+ reg = <0>;
|
|
+ compatible = "sharp,ls054b3sx01";
|
|
+ backlight = <&backlight>;
|
|
+ rotation = <270>;
|
|
+
|
|
+ iovcc-supply = <&vcc1v8_dvp>;
|
|
+ vsp-supply = <&vcc5v5_lcd>;
|
|
+ vsn-supply = <&vcc5v5_neg_lcd>;
|
|
+
|
|
+ reset-gpios = <&gpio0 RK_PB2 GPIO_ACTIVE_HIGH>;
|
|
+
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&lcd_reset_gpio>;
|
|
+
|
|
+ port {
|
|
+ mipi_in_panel: endpoint {
|
|
+ remote-endpoint = <&mipi_out_panel>;
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&i2c0 {
|
|
+ clock-frequency = <400000>;
|
|
+ i2c-scl-rising-time-ns = <168>;
|
|
+ i2c-scl-falling-time-ns = <4>;
|
|
+ status = "okay";
|
|
+
|
|
+ rk808: pmic@1b {
|
|
+ compatible = "rockchip,rk808";
|
|
+ reg = <0x1b>;
|
|
+ interrupt-parent = <&gpio3>;
|
|
+ interrupts = <10 IRQ_TYPE_LEVEL_LOW>;
|
|
+ #clock-cells = <1>;
|
|
+ clock-output-names = "xin32k", "rk808-clkout2";
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&pmic_int_l>;
|
|
+ rockchip,system-power-controller;
|
|
+ wakeup-source;
|
|
+
|
|
+ vcc1-supply = <&vcc5v0_sys>;
|
|
+ vcc2-supply = <&vcc5v0_sys>;
|
|
+ vcc3-supply = <&vcc5v0_sys>;
|
|
+ vcc4-supply = <&vcc5v0_sys>;
|
|
+ vcc6-supply = <&vcc5v0_sys>;
|
|
+ vcc7-supply = <&vcc5v0_sys>;
|
|
+ vcc8-supply = <&vcc3v3_sys>;
|
|
+ vcc9-supply = <&vcc5v0_sys>;
|
|
+ vcc10-supply = <&vcc5v0_sys>;
|
|
+ vcc11-supply = <&vcc5v0_sys>;
|
|
+ vcc12-supply = <&vcc3v3_sys>;
|
|
+ vddio-supply = <&vcca_1v8>;
|
|
+
|
|
+ rtc {
|
|
+ status = "okay";
|
|
+ };
|
|
+
|
|
+ regulators { // are all those regulator-on-in-suspend really needed?/
|
|
+ vdd_center: DCDC_REG1 {
|
|
+ regulator-name = "vdd_center";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <750000>;
|
|
+ regulator-max-microvolt = <1350000>;
|
|
+ regulator-ramp-delay = <6001>;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vdd_cpu_l: DCDC_REG2 {
|
|
+ regulator-name = "vdd_cpu_l";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <750000>;
|
|
+ regulator-max-microvolt = <1350000>;
|
|
+ regulator-ramp-delay = <6001>;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc_ddr: DCDC_REG3 {
|
|
+ regulator-name = "vcc_ddr";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc_1v8: DCDC_REG4 {
|
|
+ regulator-name = "vcc_1v8";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <1800000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <1800000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc1v8_dvp: LDO_REG1 {
|
|
+ regulator-name = "vcc1v8_dvp";
|
|
+ //regulator-always-on;
|
|
+ //regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <1800000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <1800000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc3v0_touch: LDO_REG2 {
|
|
+ regulator-name = "vcc3v0_touch";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <3300000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcca_1v8: LDO_REG3 {
|
|
+ regulator-name = "vcca_1v8";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <1800000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <1800000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc_sdio: LDO_REG4 {
|
|
+ regulator-name = "vcc_sdio";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <3300000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <3000000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcca3v0_codec: LDO_REG5 {
|
|
+ regulator-name = "vcca3v0_codec";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <3000000>;
|
|
+ regulator-max-microvolt = <3000000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc_1v5: LDO_REG6 {
|
|
+ regulator-name = "vcc_1v5";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1500000>;
|
|
+ regulator-max-microvolt = <1500000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <1500000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcca1v8_codec: LDO_REG7 {
|
|
+ regulator-name = "vcca1v8_codec";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <1800000>;
|
|
+ regulator-max-microvolt = <1800000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc_3v0: LDO_REG8 {
|
|
+ regulator-name = "vcc_3v0";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-min-microvolt = <3000000>;
|
|
+ regulator-max-microvolt = <3000000>;
|
|
+ regulator-state-mem {
|
|
+ regulator-on-in-suspend;
|
|
+ regulator-suspend-microvolt = <3000000>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc3v3_s3: vcc_lan: SWITCH_REG1 {
|
|
+ regulator-name = "vcc3v3_s3";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vcc3v3_s0: SWITCH_REG2 {
|
|
+ regulator-name = "vcc3v3_s0";
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vdd_cpu_b: regulator@40 {
|
|
+ compatible = "silergy,syr827";
|
|
+ reg = <0x40>;
|
|
+ fcs,suspend-voltage-selector = <1>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vsel1_pin>;
|
|
+ regulator-name = "vdd_cpu_b";
|
|
+ regulator-min-microvolt = <712500>;
|
|
+ regulator-max-microvolt = <1500000>;
|
|
+ regulator-ramp-delay = <1000>;
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ vdd_gpu: regulator@41 {
|
|
+ compatible = "silergy,syr828";
|
|
+ reg = <0x41>;
|
|
+ fcs,suspend-voltage-selector = <1>;
|
|
+ vsel-gpios = <&gpio1 RK_PB6 GPIO_ACTIVE_HIGH>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&vsel2_pin>;
|
|
+ regulator-name = "vdd_gpu";
|
|
+ regulator-min-microvolt = <712500>;
|
|
+ regulator-max-microvolt = <1500000>;
|
|
+ regulator-ramp-delay = <1000>;
|
|
+ regulator-always-on;
|
|
+ regulator-boot-on;
|
|
+ vin-supply = <&vcc5v0_sys>;
|
|
+
|
|
+ regulator-state-mem {
|
|
+ regulator-off-in-suspend;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ cw2015@62 {
|
|
+ compatible = "cellwise,cw2015";
|
|
+ reg = <0x62>;
|
|
+ cellwise,battery-profile = /bits/ 8 <
|
|
+ 0x15 0x7E 0x66 0x5B 0x58 0x55 0x51 0x4D
|
|
+ 0x4A 0x47 0x44 0x47 0x4D 0x46 0x32 0x27
|
|
+ 0x1F 0x1A 0x15 0x16 0x21 0x30 0x3F 0x4A
|
|
+ 0x46 0x5C 0x0C 0x29 0x19 0x31 0x59 0x74
|
|
+ 0x7B 0x7D 0x81 0x82 0x3F 0x1A 0x58 0x22
|
|
+ 0x06 0x42 0x2B 0x63 0x89 0x93 0x94 0x3C
|
|
+ 0x57 0x7D 0x93 0xAE 0x80 0xC2 0xD2 0xCB
|
|
+ 0x2F 0x00 0x64 0xA5 0xB5 0x1F 0xB0 0x11
|
|
+ >;
|
|
+ cellwise,monitor-interval-ms = <5000>;
|
|
+ power-supplies = <&mains_charger>;
|
|
+ monitored-battery = <&bat>;
|
|
+ };
|
|
+};
|
|
+
|
|
+&i2c1 {
|
|
+ clock-frequency = <100000>;
|
|
+ i2c-scl-rising-time-ns = <300>;
|
|
+ i2c-scl-falling-time-ns = <15>;
|
|
+ status = "okay";
|
|
+
|
|
+ es8316: es8316@11 {
|
|
+ compatible = "everest,es8316";
|
|
+ reg = <0x11>;
|
|
+ clocks = <&cru SCLK_I2S_8CH_OUT>;
|
|
+ clock-names = "mclk";
|
|
+ #sound-dai-cells = <0>;
|
|
+ };
|
|
+};
|
|
+
|
|
+&i2c3 {
|
|
+ i2c-scl-rising-time-ns = <450>;
|
|
+ i2c-scl-falling-time-ns = <15>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&i2c4 {
|
|
+ i2c-scl-rising-time-ns = <600>;
|
|
+ i2c-scl-falling-time-ns = <20>;
|
|
+ status = "okay";
|
|
+
|
|
+ gt9xx: gt9xx@14 {
|
|
+ compatible = "goodix,gt927";
|
|
+ goodix,config-name = "rg552_goodix_927_cfg.bin";
|
|
+ reg = <0x14>;
|
|
+ irq-gpios = <&gpio3 RK_PD7 GPIO_ACTIVE_HIGH>;
|
|
+ reset-gpios = <&gpio3 RK_PD6 GPIO_ACTIVE_HIGH>;
|
|
+ touchscreen-size-x = <1152>;
|
|
+ touchscreen-size-y = <1920>;
|
|
+ touchscreen-inverted-x;
|
|
+ touchscreen-inverted-y;
|
|
+ interrupt-parent = <&gpio3>;
|
|
+ interrupts = <RK_PD7 IRQ_TYPE_EDGE_FALLING>;
|
|
+ };
|
|
+
|
|
+ fusb0: typec-portc@22 {
|
|
+ compatible = "fcs,fusb302";
|
|
+ status = "okay";
|
|
+ reg = <0x22>;
|
|
+ interrupt-parent = <&gpio1>;
|
|
+ interrupts = <RK_PA2 IRQ_TYPE_LEVEL_LOW>;
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&fusb0_int>;
|
|
+ vbus-supply = <&vcc5v0_typec>;
|
|
+
|
|
+ connector {
|
|
+ compatible = "usb-c-connector";
|
|
+ data-role = "dual";
|
|
+ label = "USB-C";
|
|
+ op-sink-microwatt = <1000000>;
|
|
+ power-role = "dual";
|
|
+ sink-pdos =
|
|
+ <PDO_FIXED(5000, 2500, PDO_FIXED_USB_COMM)>;
|
|
+ source-pdos =
|
|
+ <PDO_FIXED(5000, 1400, PDO_FIXED_USB_COMM)>;
|
|
+ try-power-role = "sink";
|
|
+
|
|
+ ports {
|
|
+ #address-cells = <1>;
|
|
+ #size-cells = <0>;
|
|
+
|
|
+ port@0 {
|
|
+ reg = <0>;
|
|
+
|
|
+ usbc_hs: endpoint {
|
|
+ remote-endpoint = <&u2phy0_typec_hs>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ port@1 {
|
|
+ reg = <1>;
|
|
+
|
|
+ usbc_ss: endpoint {
|
|
+ remote-endpoint = <&tcphy0_typec_ss>;
|
|
+ };
|
|
+ };
|
|
+ // displayport maybe?
|
|
+ };
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&i2s1 {
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&i2s_8ch_mclk_pin>, <&i2s1_2ch_bus>;
|
|
+ rockchip,i2s-broken-burst-len;
|
|
+ rockchip,playback-channels = <8>;
|
|
+ rockchip,capture-channels = <8>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&i2s2 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&io_domains {
|
|
+ status = "okay";
|
|
+
|
|
+ bt656-supply = <&vcc1v8_dvp>;
|
|
+ audio-supply = <&vcca3v0_codec>;
|
|
+ sdmmc-supply = <&vcc_sdio>;
|
|
+ gpio1830-supply = <&vcc_3v0>;
|
|
+};
|
|
+
|
|
+&pmu_io_domains {
|
|
+ pmu1830-supply = <&vcc_3v0>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&pinctrl {
|
|
+ dc-charger {
|
|
+ dc_det_pin: dc-det-pin {
|
|
+ rockchip,pins = <4 RK_PD0 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ es8316 {
|
|
+ hp_det_pin: hp-det-pin {
|
|
+ rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+
|
|
+ spk_en_pin: spk-en-pin {
|
|
+ rockchip,pins = <1 RK_PC5 RK_FUNC_GPIO &pcfg_pull_down>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ i2s1 {
|
|
+ i2s_8ch_mclk_pin: i2s-8ch-mclk-pin {
|
|
+ rockchip,pins = <4 RK_PA0 1 &pcfg_pull_none>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ fusb302x {
|
|
+ fusb0_int: fusb0-int {
|
|
+ rockchip,pins = <1 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ pmic {
|
|
+ pmic_int_l: pmic-int-l {
|
|
+ rockchip,pins = <3 RK_PB2 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+
|
|
+ vsel1_pin: vsel1-pin {
|
|
+ rockchip,pins = <1 RK_PC1 RK_FUNC_GPIO &pcfg_pull_down>;
|
|
+ };
|
|
+
|
|
+ vsel2_pin: vsel2-pin {
|
|
+ rockchip,pins = <1 RK_PB6 RK_FUNC_GPIO &pcfg_pull_down>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ sdcard {
|
|
+ sdmmc0_pwr_h: sdmmc0-pwr-h {
|
|
+ rockchip,pins = <0 RK_PA1 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+
|
|
+ };
|
|
+
|
|
+ sdio-pwrseq {
|
|
+ wifi_enable_h: wifi-enable-h {
|
|
+ rockchip,pins = <2 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ usb-typec {
|
|
+ vcc5v0_typec_en: vcc5v0_typec_en {
|
|
+ rockchip,pins = <1 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ usb2 {
|
|
+ vcc5v0_host_en: vcc5v0-host-en {
|
|
+ rockchip,pins = <4 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ gpio-leds {
|
|
+ leds_gpio: leds-gpio {
|
|
+ rockchip,pins =
|
|
+ <1 RK_PC4 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PD5 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ lcd-panel {
|
|
+ lcd_reset_gpio: lcd-reset-gpio {
|
|
+ rockchip,pins = <0 RK_PB2 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+
|
|
+ vcc5v5_lcd_en: vcc5v5-lcd-en {
|
|
+ rockchip,pins = <0 RK_PD3 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+
|
|
+ vcc5v5_neg_lcd_en: vcc5v5-neg-lcd-en {
|
|
+ rockchip,pins = <0 RK_PD1 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ wifi {
|
|
+ wifi_pwr: wifi-pwr-en {
|
|
+ rockchip,pins = <3 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>;
|
|
+ };
|
|
+ };
|
|
+
|
|
+ btns {
|
|
+ btn_pins: btn-pins {
|
|
+ rockchip,pins =
|
|
+ <3 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA7 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PD0 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PD1 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PD2 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PD3 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB3 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB4 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB0 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB1 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PC0 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ vol_pwr_btn: vol-pwr-btn {
|
|
+ rockchip,pins =
|
|
+ <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>,
|
|
+ <3 RK_PB6 RK_FUNC_GPIO &pcfg_pull_up>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&tcphy0 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&tcphy0_usb3 {
|
|
+ port {
|
|
+ tcphy0_typec_ss: endpoint {
|
|
+ remote-endpoint = <&usbc_ss>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&tcphy1 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&tsadc {
|
|
+ /* tshut mode 0:CRU 1:GPIO */
|
|
+ rockchip,hw-tshut-mode = <1>;
|
|
+ /* tshut polarity 0:LOW 1:HIGH */
|
|
+ rockchip,hw-tshut-polarity = <1>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&u2phy0 {
|
|
+ status = "okay";
|
|
+
|
|
+ u2phy0_otg: otg-port {
|
|
+ status = "okay";
|
|
+ };
|
|
+
|
|
+ u2phy0_host: host-port {
|
|
+ phy-supply = <&vcc5v0_host>;
|
|
+ status = "okay";
|
|
+ };
|
|
+
|
|
+ port {
|
|
+ u2phy0_typec_hs: endpoint {
|
|
+ remote-endpoint = <&usbc_hs>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&u2phy1 {
|
|
+ status = "okay";
|
|
+
|
|
+ u2phy1_otg: otg-port {
|
|
+ status = "okay";
|
|
+ };
|
|
+
|
|
+ u2phy1_host: host-port {
|
|
+ phy-supply = <&vcc5v0_host>;
|
|
+ status = "okay";
|
|
+ };
|
|
+};
|
|
+
|
|
+&uart0 {
|
|
+ pinctrl-names = "default";
|
|
+ pinctrl-0 = <&uart0_xfer &uart0_cts &uart0_rts>;
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&uart2 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usb_host0_ehci {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usb_host0_ohci {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usb_host1_ehci {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usb_host1_ohci {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usbdrd3_0 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usbdrd_dwc3_0 {
|
|
+ status = "okay";
|
|
+ dr_mode = "host";
|
|
+};
|
|
+
|
|
+&usbdrd3_1 {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&usbdrd_dwc3_1 {
|
|
+ status = "okay";
|
|
+ dr_mode = "host";
|
|
+ #address-cells = <1>;
|
|
+ #size-cells = <0>;
|
|
+
|
|
+ wifi_card: device@1 {
|
|
+ compatible = "usbbda,f179";
|
|
+ reg = <1>;
|
|
+ #size-cells = <0>;
|
|
+ #address-cells = <2>;
|
|
+
|
|
+ interface@0 {
|
|
+ compatible = "usbifbda,f179.config1.0";
|
|
+ reg = <0 1>;
|
|
+ };
|
|
+ };
|
|
+};
|
|
+
|
|
+&vopb {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&vopb_mmu {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&vopl {
|
|
+ status = "okay";
|
|
+};
|
|
+
|
|
+&vopl_mmu {
|
|
+ status = "okay";
|
|
+};
|
|
diff -rupN linux.orig/drivers/gpu/drm/panel/Kconfig linux/drivers/gpu/drm/panel/Kconfig
|
|
--- linux.orig/drivers/gpu/drm/panel/Kconfig 2022-11-01 17:55:26.614499464 -0400
|
|
+++ linux/drivers/gpu/drm/panel/Kconfig 2022-11-01 17:56:17.136793634 -0400
|
|
@@ -588,6 +588,15 @@ config DRM_PANEL_SHARP_LS043T1LE01
|
|
Say Y here if you want to enable support for Sharp LS043T1LE01 qHD
|
|
(540x960) DSI panel as found on the Qualcomm APQ8074 Dragonboard
|
|
|
|
+config DRM_PANEL_SHARP_LS054B3SX01
|
|
+ bool "Sharp LS054B3SX01 1152x1080 video mode panel"
|
|
+ depends on OF
|
|
+ depends on DRM_MIPI_DSI
|
|
+ depends on BACKLIGHT_CLASS_DEVICE
|
|
+ help
|
|
+ say Y here if you want to enable support for Sharp LS054B3SX01
|
|
+ 1152x1080 panel as found in Anbernic RG552.
|
|
+
|
|
config DRM_PANEL_SHARP_LS060T1SX01
|
|
tristate "Sharp LS060T1SX01 FullHD video mode panel"
|
|
depends on OF
|
|
diff -rupN linux.orig/drivers/gpu/drm/panel/Makefile linux/drivers/gpu/drm/panel/Makefile
|
|
--- linux.orig/drivers/gpu/drm/panel/Makefile 2022-11-01 17:55:26.614499464 -0400
|
|
+++ linux/drivers/gpu/drm/panel/Makefile 2022-11-01 17:56:17.136793634 -0400
|
|
@@ -59,6 +59,7 @@ obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) +=
|
|
obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o
|
|
obj-$(CONFIG_DRM_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o
|
|
obj-$(CONFIG_DRM_PANEL_SHARP_LS043T1LE01) += panel-sharp-ls043t1le01.o
|
|
+obj-$(CONFIG_DRM_PANEL_SHARP_LS054B3SX01) += panel-sharp-ls054b3sx01.o
|
|
obj-$(CONFIG_DRM_PANEL_SHARP_LS060T1SX01) += panel-sharp-ls060t1sx01.o
|
|
obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7701) += panel-sitronix-st7701.o
|
|
obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7703) += panel-sitronix-st7703.o
|
|
diff -rupN linux.orig/drivers/gpu/drm/panel/panel-sharp-ls054b3sx01.c linux/drivers/gpu/drm/panel/panel-sharp-ls054b3sx01.c
|
|
--- linux.orig/drivers/gpu/drm/panel/panel-sharp-ls054b3sx01.c 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/drivers/gpu/drm/panel/panel-sharp-ls054b3sx01.c 2022-11-01 17:58:24.801136793 -0400
|
|
@@ -0,0 +1,368 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-only
|
|
+/*
|
|
+ * Copyright (c) 2022 Maya Matuszczyk <maccraft123mc@gmail.com>
|
|
+ */
|
|
+
|
|
+#include <linux/delay.h>
|
|
+#include <linux/gpio/consumer.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/of.h>
|
|
+#include <linux/regulator/consumer.h>
|
|
+
|
|
+#include <video/mipi_display.h>
|
|
+
|
|
+#include <drm/drm_mipi_dsi.h>
|
|
+#include <drm/drm_modes.h>
|
|
+#include <drm/drm_panel.h>
|
|
+
|
|
+struct sharp_ls054 {
|
|
+ struct drm_panel panel;
|
|
+ struct mipi_dsi_device *dsi;
|
|
+ struct regulator *iovcc_supply;
|
|
+ struct regulator *vsp_supply;
|
|
+ struct regulator *vsn_supply;
|
|
+ struct gpio_desc *reset_gpio;
|
|
+ enum drm_panel_orientation orientation;
|
|
+ bool prepared;
|
|
+};
|
|
+
|
|
+static inline struct sharp_ls054 *to_sharp_ls054(struct drm_panel *panel)
|
|
+{
|
|
+ return container_of(panel, struct sharp_ls054, panel);
|
|
+}
|
|
+
|
|
+#define dsi_dcs_write_seq(dsi, cmd, seq...) do { \
|
|
+ static const u8 b[] = { cmd, seq }; \
|
|
+ int ret; \
|
|
+ ret = mipi_dsi_dcs_write_buffer(dsi, b, ARRAY_SIZE(b)); \
|
|
+ if (ret < 0) \
|
|
+ return ret; \
|
|
+ } while (0)
|
|
+
|
|
+#define SHARP_LS054_SETEXTC 0xB9
|
|
+#define SHARP_LS054_SETSEQUENCE 0xB0
|
|
+#define SHARP_LS054_SETGAMMACURVE 0xE0
|
|
+#define SHARP_LS054_SETPOWER 0xB1
|
|
+#define SHARP_LS054_SETVREF 0xD2
|
|
+#define SHARP_LS054_SETGIP0 0xD3
|
|
+#define SHARP_LS054_SETGIP1 0xD5
|
|
+#define SHARP_LS054_SETGIP2 0xD6
|
|
+#define SHARP_LS054_SETGIP3 0xD8
|
|
+#define SHARP_LS054_SETDISP 0xB2
|
|
+#define SHARP_LS054_SETCYC 0xB4
|
|
+#define SHARP_LS054_SETMIPI 0xBA
|
|
+#define SHARP_LS054_SETPTBA 0xBF
|
|
+
|
|
+static int sharp_ls054_init_sequence(struct sharp_ls054 *ctx)
|
|
+{
|
|
+ struct mipi_dsi_device *dsi = ctx->dsi;
|
|
+ int ret;
|
|
+
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETEXTC,
|
|
+ 0xFF, 0x83, 0x99);
|
|
+ //dsi_dcs_write_seq(dsi, SHARP_LS054_SETSEQUENCE,
|
|
+ // 0x00, 0x00, 0x65);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETGAMMACURVE,
|
|
+ 0x01, 0x13, 0x17, 0x34, 0x38, 0x3E, 0x2C, 0x47,
|
|
+ 0x07, 0x0C, 0x0F, 0x12, 0x14, 0x11, 0x13, 0x12,
|
|
+ 0x18, 0x0B, 0x17, 0x07, 0x13, 0x02, 0x14, 0x18,
|
|
+ 0x32, 0x37, 0x3D, 0x29, 0x43, 0x07, 0x0E, 0x0C,
|
|
+ 0x0F, 0x11, 0x10, 0x12, 0x12, 0x18, 0x0C, 0x17,
|
|
+ 0x07, 0x13);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETPOWER,
|
|
+ 0x00, 0x7C, 0x38, 0x35, 0x99, 0x09, 0x22, 0x22,
|
|
+ 0x72, 0xF2, 0x68, 0x58);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETVREF,
|
|
+ 0x99);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETGIP0,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00,
|
|
+ 0x10, 0x05, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07,
|
|
+ 0x07, 0x03, 0x00, 0x00, 0x00, 0x05, 0x08);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETGIP1,
|
|
+ 0x00, 0x00, 0x01, 0x00, 0x03, 0x02, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x19, 0x00, 0x18, 0x00, 0x21, 0x20,
|
|
+ 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x32, 0x32, 0x31, 0x31, 0x30, 0x30);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETGIP2,
|
|
+ 0x40, 0x40, 0x02, 0x03, 0x00, 0x01, 0x40, 0x40,
|
|
+ 0x40, 0x40, 0x18, 0x40, 0x19, 0x40, 0x20, 0x21,
|
|
+ 0x40, 0x18, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
+ 0x40, 0x40, 0x32, 0x32, 0x31, 0x31, 0x30, 0x30);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETGIP3,
|
|
+ 0x28, 0x2A, 0x00, 0x2A, 0x28, 0x02, 0xC0, 0x2A,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
+ 0x28, 0x02, 0x00, 0x2A, 0x28, 0x02, 0xC0, 0x2A);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETDISP,
|
|
+ 0x00, 0x80, 0x10, 0x7F, 0x05, 0x01, 0x23, 0x4D,
|
|
+ 0x21, 0x01);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETCYC,
|
|
+ 0x00, 0x3F, 0x00, 0x41, 0x00, 0x3D, 0x00, 0x00,
|
|
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x0F, 0x01, 0x02,
|
|
+ 0x05, 0x40, 0x00, 0x00, 0x3A, 0x00, 0x41, 0x00,
|
|
+ 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
+ 0x0F, 0x01, 0x02, 0x05, 0x00, 0x00, 0x00, 0x3A);
|
|
+ dsi_dcs_write_seq(dsi, SHARP_LS054_SETMIPI,
|
|
+ 0x03, 0x82, 0xA0, 0xE5);
|
|
+ //dsi_dcs_write_seq(dsi, SHARP_LS054_SETPTBA,
|
|
+ // 0xCF, 0x00, 0x46, 0x00, 0x00, 0x00, 0x02, 0x54,
|
|
+ // 0x04, 0x61, 0x1C, 0x8C);
|
|
+
|
|
+
|
|
+ ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
|
|
+ if (ret < 0)
|
|
+ {
|
|
+ dev_err(&dsi->dev, "Failed to exit sleep mode: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+ msleep(130);
|
|
+
|
|
+ dsi_dcs_write_seq(dsi, 0x29);
|
|
+ ret = mipi_dsi_dcs_set_display_on(dsi);
|
|
+ if (ret < 0)
|
|
+ {
|
|
+ dev_err(&dsi->dev, "Failed to set display on: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+ msleep(50);
|
|
+
|
|
+ mipi_dsi_dcs_set_display_brightness(dsi, 0xFF);
|
|
+ dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
|
|
+ dsi_dcs_write_seq(dsi, 0x53, 0x24); //MIPI_DCS_WRITE_CONTROL_DISPLAY ?
|
|
+ mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int sharp_ls054_prepare(struct drm_panel *panel)
|
|
+{
|
|
+ struct sharp_ls054 *ctx = to_sharp_ls054(panel);
|
|
+ struct mipi_dsi_device *dsi = ctx->dsi;
|
|
+ struct device *dev = &ctx->dsi->dev;
|
|
+ int ret;
|
|
+
|
|
+ if (ctx->prepared)
|
|
+ return 0;
|
|
+
|
|
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
|
|
+
|
|
+ ret = regulator_enable(ctx->iovcc_supply);
|
|
+ if (ret < 0)
|
|
+ return ret;
|
|
+
|
|
+ usleep_range(1500, 3000);
|
|
+
|
|
+ ret = regulator_enable(ctx->vsp_supply);
|
|
+ if (ret < 0)
|
|
+ goto err_vsp;
|
|
+
|
|
+ usleep_range(1500, 3000);
|
|
+
|
|
+ ret = regulator_enable(ctx->vsn_supply);
|
|
+ if (ret < 0)
|
|
+ goto err_on;
|
|
+
|
|
+ // TODO: move resetting into its own function
|
|
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
|
|
+
|
|
+ msleep(200);
|
|
+
|
|
+ ret = sharp_ls054_init_sequence(ctx);
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "Failed to initialize panel: %d\n", ret);
|
|
+ goto err_on;
|
|
+ }
|
|
+
|
|
+ ctx->prepared = true;
|
|
+
|
|
+ return 0;
|
|
+
|
|
+ // TODO: make sure those labels are ok
|
|
+err_on:
|
|
+ regulator_disable(ctx->vsn_supply);
|
|
+
|
|
+err_vsp:
|
|
+ regulator_disable(ctx->vsp_supply);
|
|
+
|
|
+err_iovcc:
|
|
+ regulator_disable(ctx->iovcc_supply);
|
|
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+// FIXME
|
|
+static int sharp_ls054_unprepare(struct drm_panel *panel)
|
|
+{
|
|
+ struct sharp_ls054 *ctx = to_sharp_ls054(panel);
|
|
+ struct mipi_dsi_device *dsi = ctx->dsi;
|
|
+ struct device *dev = &ctx->dsi->dev;
|
|
+ int ret;
|
|
+
|
|
+ if (!ctx->prepared)
|
|
+ return 0;
|
|
+
|
|
+ ret = mipi_dsi_dcs_set_display_off(dsi);
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "Failed to set display off: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+ usleep_range(2000, 3000);
|
|
+
|
|
+ ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+ msleep(5);
|
|
+
|
|
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
|
|
+
|
|
+ usleep_range(500, 1000);
|
|
+ regulator_disable(ctx->vsn_supply);
|
|
+ usleep_range(500, 1000);
|
|
+ regulator_disable(ctx->vsp_supply);
|
|
+ usleep_range(500, 1000);
|
|
+ regulator_disable(ctx->iovcc_supply);
|
|
+
|
|
+ ctx->prepared = false;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+// FIXME: should we strive for perfect 60hz?
|
|
+static const struct drm_display_mode sharp_ls054_mode = {
|
|
+ .clock = ((1152 + 64 + 4 + 32) * (1920 + 56 + 3 + 6) * 60) / 1000,
|
|
+ .hdisplay = 1152,
|
|
+ .hsync_start = 1152 + 64,
|
|
+ .hsync_end = 1152 + 64 + 4,
|
|
+ .htotal = 1152 + 64 + 4 + 32,
|
|
+ .vdisplay = 1920,
|
|
+ .vsync_start = 1920 + 56,
|
|
+ .vsync_end = 1920 + 56 + 3,
|
|
+ .vtotal = 1920 + 56 + 3 + 6,
|
|
+ .width_mm = 70,
|
|
+ .height_mm = 117,
|
|
+ .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
|
|
+};
|
|
+
|
|
+static int sharp_ls054_get_modes(struct drm_panel *panel,
|
|
+ struct drm_connector *connector)
|
|
+{
|
|
+ struct sharp_ls054 *ctx = to_sharp_ls054(panel);
|
|
+ struct drm_display_mode *mode;
|
|
+
|
|
+ mode = drm_mode_duplicate(connector->dev, &sharp_ls054_mode);
|
|
+ if (!mode)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ drm_mode_set_name(mode);
|
|
+
|
|
+ mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
|
|
+ connector->display_info.width_mm = mode->width_mm;
|
|
+ connector->display_info.height_mm = mode->height_mm;
|
|
+ drm_mode_probed_add(connector, mode);
|
|
+ drm_connector_set_panel_orientation(connector, ctx->orientation);
|
|
+
|
|
+ return 1;
|
|
+}
|
|
+
|
|
+static const struct drm_panel_funcs sharp_ls054_panel_funcs = {
|
|
+ .prepare = sharp_ls054_prepare,
|
|
+ .unprepare = sharp_ls054_unprepare,
|
|
+ .get_modes = sharp_ls054_get_modes,
|
|
+};
|
|
+
|
|
+static int sharp_ls054_probe(struct mipi_dsi_device *dsi)
|
|
+{
|
|
+ struct device *dev = &dsi->dev;
|
|
+ struct sharp_ls054 *ctx;
|
|
+ int ret;
|
|
+
|
|
+ ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
|
|
+ if (!ctx)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ ctx->iovcc_supply = devm_regulator_get(dev, "iovcc");
|
|
+ if (IS_ERR(ctx->iovcc_supply))
|
|
+ return PTR_ERR(ctx->iovcc_supply); // TODO: replace with dev_err_probe
|
|
+
|
|
+ ctx->vsp_supply = devm_regulator_get(dev, "vsp");
|
|
+ if (IS_ERR(ctx->vsp_supply))
|
|
+ return PTR_ERR(ctx->vsp_supply);
|
|
+
|
|
+ ctx->vsn_supply = devm_regulator_get(dev, "vsn");
|
|
+ if (IS_ERR(ctx->vsn_supply))
|
|
+ return PTR_ERR(ctx->vsn_supply);
|
|
+
|
|
+ ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
|
|
+ if (IS_ERR(ctx->reset_gpio))
|
|
+ return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
|
|
+ "Failed to get reset-gpios\n");
|
|
+
|
|
+ ret = of_drm_get_panel_orientation(dev->of_node, &ctx->orientation);
|
|
+ if (ret < 0)
|
|
+ dev_err(dev, "%pOF: failed to get orientation, %d\n", dev->of_node, ret);
|
|
+
|
|
+ ctx->dsi = dsi;
|
|
+ mipi_dsi_set_drvdata(dsi, ctx);
|
|
+
|
|
+ dsi->lanes = 4;
|
|
+ dsi->format = MIPI_DSI_FMT_RGB888;
|
|
+ dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
|
|
+ MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_NO_EOT_PACKET |
|
|
+ MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_VIDEO_AUTO_VERT;
|
|
+ // are all those flags really needed?
|
|
+
|
|
+ drm_panel_init(&ctx->panel, dev, &sharp_ls054_panel_funcs,
|
|
+ DRM_MODE_CONNECTOR_DSI);
|
|
+
|
|
+ ret = drm_panel_of_backlight(&ctx->panel);
|
|
+ if (ret)
|
|
+ return dev_err_probe(dev, ret, "Failed to get backlight\n");
|
|
+
|
|
+ drm_panel_add(&ctx->panel);
|
|
+
|
|
+ ret = mipi_dsi_attach(dsi);
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
|
|
+ drm_panel_remove(&ctx->panel);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void sharp_ls054_remove(struct mipi_dsi_device *dsi)
|
|
+{
|
|
+ struct sharp_ls054 *ctx = mipi_dsi_get_drvdata(dsi);
|
|
+ int ret;
|
|
+
|
|
+ ret = mipi_dsi_detach(dsi);
|
|
+ if (ret < 0)
|
|
+ dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
|
|
+
|
|
+ drm_panel_remove(&ctx->panel);
|
|
+}
|
|
+
|
|
+static const struct of_device_id sharp_ls054b3sx01_of_match[] = {
|
|
+ { .compatible = "sharp,ls054b3sx01" },
|
|
+ { /* sentinel */ }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, sharp_ls054b3sx01_of_match);
|
|
+
|
|
+static struct mipi_dsi_driver sharp_ls054_driver = {
|
|
+ .probe = sharp_ls054_probe,
|
|
+ .remove = sharp_ls054_remove,
|
|
+ .driver = {
|
|
+ .name = "panel-sharp-ls054b3sx01",
|
|
+ .of_match_table = sharp_ls054b3sx01_of_match,
|
|
+ },
|
|
+};
|
|
+module_mipi_dsi_driver(sharp_ls054_driver);
|
|
+
|
|
+MODULE_AUTHOR("Maya Matuszczyk <maccraft123mc@gmail.com>");
|
|
+MODULE_DESCRIPTION("Panel driver for Sharp LS054B3SX01 1152x1080 Video Mode DSI Panel");
|
|
+MODULE_LICENSE("GPL v2");
|
|
diff -rupN linux.orig/drivers/input/input-polldev.c linux/drivers/input/input-polldev.c
|
|
--- linux.orig/drivers/input/input-polldev.c 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/drivers/input/input-polldev.c 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -0,0 +1,362 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-only
|
|
+/*
|
|
+ * Generic implementation of a polled input device
|
|
+
|
|
+ * Copyright (c) 2007 Dmitry Torokhov
|
|
+ */
|
|
+
|
|
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
+
|
|
+#include <linux/jiffies.h>
|
|
+#include <linux/slab.h>
|
|
+#include <linux/mutex.h>
|
|
+#include <linux/workqueue.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/input-polldev.h>
|
|
+
|
|
+MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
|
|
+MODULE_DESCRIPTION("Generic implementation of a polled input device");
|
|
+MODULE_LICENSE("GPL v2");
|
|
+
|
|
+static void input_polldev_queue_work(struct input_polled_dev *dev)
|
|
+{
|
|
+ unsigned long delay;
|
|
+
|
|
+ delay = msecs_to_jiffies(dev->poll_interval);
|
|
+ if (delay >= HZ)
|
|
+ delay = round_jiffies_relative(delay);
|
|
+
|
|
+ queue_delayed_work(system_freezable_wq, &dev->work, delay);
|
|
+}
|
|
+
|
|
+static void input_polled_device_work(struct work_struct *work)
|
|
+{
|
|
+ struct input_polled_dev *dev =
|
|
+ container_of(work, struct input_polled_dev, work.work);
|
|
+
|
|
+ dev->poll(dev);
|
|
+ input_polldev_queue_work(dev);
|
|
+}
|
|
+
|
|
+static int input_open_polled_device(struct input_dev *input)
|
|
+{
|
|
+ struct input_polled_dev *dev = input_get_drvdata(input);
|
|
+
|
|
+ if (dev->open)
|
|
+ dev->open(dev);
|
|
+
|
|
+ /* Only start polling if polling is enabled */
|
|
+ if (dev->poll_interval > 0) {
|
|
+ dev->poll(dev);
|
|
+ input_polldev_queue_work(dev);
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void input_close_polled_device(struct input_dev *input)
|
|
+{
|
|
+ struct input_polled_dev *dev = input_get_drvdata(input);
|
|
+
|
|
+ cancel_delayed_work_sync(&dev->work);
|
|
+
|
|
+ if (dev->close)
|
|
+ dev->close(dev);
|
|
+}
|
|
+
|
|
+/* SYSFS interface */
|
|
+
|
|
+static ssize_t input_polldev_get_poll(struct device *dev,
|
|
+ struct device_attribute *attr, char *buf)
|
|
+{
|
|
+ struct input_polled_dev *polldev = dev_get_drvdata(dev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", polldev->poll_interval);
|
|
+}
|
|
+
|
|
+static ssize_t input_polldev_set_poll(struct device *dev,
|
|
+ struct device_attribute *attr, const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct input_polled_dev *polldev = dev_get_drvdata(dev);
|
|
+ struct input_dev *input = polldev->input;
|
|
+ unsigned int interval;
|
|
+ int err;
|
|
+
|
|
+ err = kstrtouint(buf, 0, &interval);
|
|
+ if (err)
|
|
+ return err;
|
|
+
|
|
+ if (interval < polldev->poll_interval_min)
|
|
+ return -EINVAL;
|
|
+
|
|
+ if (interval > polldev->poll_interval_max)
|
|
+ return -EINVAL;
|
|
+
|
|
+ mutex_lock(&input->mutex);
|
|
+
|
|
+ polldev->poll_interval = interval;
|
|
+
|
|
+ if (input->users) {
|
|
+ cancel_delayed_work_sync(&polldev->work);
|
|
+ if (polldev->poll_interval > 0)
|
|
+ input_polldev_queue_work(polldev);
|
|
+ }
|
|
+
|
|
+ mutex_unlock(&input->mutex);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+static DEVICE_ATTR(poll, S_IRUGO | S_IWUSR, input_polldev_get_poll,
|
|
+ input_polldev_set_poll);
|
|
+
|
|
+
|
|
+static ssize_t input_polldev_get_max(struct device *dev,
|
|
+ struct device_attribute *attr, char *buf)
|
|
+{
|
|
+ struct input_polled_dev *polldev = dev_get_drvdata(dev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", polldev->poll_interval_max);
|
|
+}
|
|
+
|
|
+static DEVICE_ATTR(max, S_IRUGO, input_polldev_get_max, NULL);
|
|
+
|
|
+static ssize_t input_polldev_get_min(struct device *dev,
|
|
+ struct device_attribute *attr, char *buf)
|
|
+{
|
|
+ struct input_polled_dev *polldev = dev_get_drvdata(dev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", polldev->poll_interval_min);
|
|
+}
|
|
+
|
|
+static DEVICE_ATTR(min, S_IRUGO, input_polldev_get_min, NULL);
|
|
+
|
|
+static struct attribute *sysfs_attrs[] = {
|
|
+ &dev_attr_poll.attr,
|
|
+ &dev_attr_max.attr,
|
|
+ &dev_attr_min.attr,
|
|
+ NULL
|
|
+};
|
|
+
|
|
+static struct attribute_group input_polldev_attribute_group = {
|
|
+ .attrs = sysfs_attrs
|
|
+};
|
|
+
|
|
+static const struct attribute_group *input_polldev_attribute_groups[] = {
|
|
+ &input_polldev_attribute_group,
|
|
+ NULL
|
|
+};
|
|
+
|
|
+/**
|
|
+ * input_allocate_polled_device - allocate memory for polled device
|
|
+ *
|
|
+ * The function allocates memory for a polled device and also
|
|
+ * for an input device associated with this polled device.
|
|
+ */
|
|
+struct input_polled_dev *input_allocate_polled_device(void)
|
|
+{
|
|
+ struct input_polled_dev *dev;
|
|
+
|
|
+ dev = kzalloc(sizeof(struct input_polled_dev), GFP_KERNEL);
|
|
+ if (!dev)
|
|
+ return NULL;
|
|
+
|
|
+ dev->input = input_allocate_device();
|
|
+ if (!dev->input) {
|
|
+ kfree(dev);
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ return dev;
|
|
+}
|
|
+EXPORT_SYMBOL(input_allocate_polled_device);
|
|
+
|
|
+struct input_polled_devres {
|
|
+ struct input_polled_dev *polldev;
|
|
+};
|
|
+
|
|
+static int devm_input_polldev_match(struct device *dev, void *res, void *data)
|
|
+{
|
|
+ struct input_polled_devres *devres = res;
|
|
+
|
|
+ return devres->polldev == data;
|
|
+}
|
|
+
|
|
+static void devm_input_polldev_release(struct device *dev, void *res)
|
|
+{
|
|
+ struct input_polled_devres *devres = res;
|
|
+ struct input_polled_dev *polldev = devres->polldev;
|
|
+
|
|
+ dev_dbg(dev, "%s: dropping reference/freeing %s\n",
|
|
+ __func__, dev_name(&polldev->input->dev));
|
|
+
|
|
+ input_put_device(polldev->input);
|
|
+ kfree(polldev);
|
|
+}
|
|
+
|
|
+static void devm_input_polldev_unregister(struct device *dev, void *res)
|
|
+{
|
|
+ struct input_polled_devres *devres = res;
|
|
+ struct input_polled_dev *polldev = devres->polldev;
|
|
+
|
|
+ dev_dbg(dev, "%s: unregistering device %s\n",
|
|
+ __func__, dev_name(&polldev->input->dev));
|
|
+ input_unregister_device(polldev->input);
|
|
+
|
|
+ /*
|
|
+ * Note that we are still holding extra reference to the input
|
|
+ * device so it will stick around until devm_input_polldev_release()
|
|
+ * is called.
|
|
+ */
|
|
+}
|
|
+
|
|
+/**
|
|
+ * devm_input_allocate_polled_device - allocate managed polled device
|
|
+ * @dev: device owning the polled device being created
|
|
+ *
|
|
+ * Returns prepared &struct input_polled_dev or %NULL.
|
|
+ *
|
|
+ * Managed polled input devices do not need to be explicitly unregistered
|
|
+ * or freed as it will be done automatically when owner device unbinds
|
|
+ * from * its driver (or binding fails). Once such managed polled device
|
|
+ * is allocated, it is ready to be set up and registered in the same
|
|
+ * fashion as regular polled input devices (using
|
|
+ * input_register_polled_device() function).
|
|
+ *
|
|
+ * If you want to manually unregister and free such managed polled devices,
|
|
+ * it can be still done by calling input_unregister_polled_device() and
|
|
+ * input_free_polled_device(), although it is rarely needed.
|
|
+ *
|
|
+ * NOTE: the owner device is set up as parent of input device and users
|
|
+ * should not override it.
|
|
+ */
|
|
+struct input_polled_dev *devm_input_allocate_polled_device(struct device *dev)
|
|
+{
|
|
+ struct input_polled_dev *polldev;
|
|
+ struct input_polled_devres *devres;
|
|
+
|
|
+ devres = devres_alloc(devm_input_polldev_release, sizeof(*devres),
|
|
+ GFP_KERNEL);
|
|
+ if (!devres)
|
|
+ return NULL;
|
|
+
|
|
+ polldev = input_allocate_polled_device();
|
|
+ if (!polldev) {
|
|
+ devres_free(devres);
|
|
+ return NULL;
|
|
+ }
|
|
+
|
|
+ polldev->input->dev.parent = dev;
|
|
+ polldev->devres_managed = true;
|
|
+
|
|
+ devres->polldev = polldev;
|
|
+ devres_add(dev, devres);
|
|
+
|
|
+ return polldev;
|
|
+}
|
|
+EXPORT_SYMBOL(devm_input_allocate_polled_device);
|
|
+
|
|
+/**
|
|
+ * input_free_polled_device - free memory allocated for polled device
|
|
+ * @dev: device to free
|
|
+ *
|
|
+ * The function frees memory allocated for polling device and drops
|
|
+ * reference to the associated input device.
|
|
+ */
|
|
+void input_free_polled_device(struct input_polled_dev *dev)
|
|
+{
|
|
+ if (dev) {
|
|
+ if (dev->devres_managed)
|
|
+ WARN_ON(devres_destroy(dev->input->dev.parent,
|
|
+ devm_input_polldev_release,
|
|
+ devm_input_polldev_match,
|
|
+ dev));
|
|
+ input_put_device(dev->input);
|
|
+ kfree(dev);
|
|
+ }
|
|
+}
|
|
+EXPORT_SYMBOL(input_free_polled_device);
|
|
+
|
|
+/**
|
|
+ * input_register_polled_device - register polled device
|
|
+ * @dev: device to register
|
|
+ *
|
|
+ * The function registers previously initialized polled input device
|
|
+ * with input layer. The device should be allocated with call to
|
|
+ * input_allocate_polled_device(). Callers should also set up poll()
|
|
+ * method and set up capabilities (id, name, phys, bits) of the
|
|
+ * corresponding input_dev structure.
|
|
+ */
|
|
+int input_register_polled_device(struct input_polled_dev *dev)
|
|
+{
|
|
+ struct input_polled_devres *devres = NULL;
|
|
+ struct input_dev *input = dev->input;
|
|
+ int error;
|
|
+
|
|
+ if (dev->devres_managed) {
|
|
+ devres = devres_alloc(devm_input_polldev_unregister,
|
|
+ sizeof(*devres), GFP_KERNEL);
|
|
+ if (!devres)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ devres->polldev = dev;
|
|
+ }
|
|
+
|
|
+ input_set_drvdata(input, dev);
|
|
+ INIT_DELAYED_WORK(&dev->work, input_polled_device_work);
|
|
+
|
|
+ if (!dev->poll_interval)
|
|
+ dev->poll_interval = 500;
|
|
+ if (!dev->poll_interval_max)
|
|
+ dev->poll_interval_max = dev->poll_interval;
|
|
+
|
|
+ input->open = input_open_polled_device;
|
|
+ input->close = input_close_polled_device;
|
|
+
|
|
+ input->dev.groups = input_polldev_attribute_groups;
|
|
+
|
|
+ error = input_register_device(input);
|
|
+ if (error) {
|
|
+ devres_free(devres);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ /*
|
|
+ * Take extra reference to the underlying input device so
|
|
+ * that it survives call to input_unregister_polled_device()
|
|
+ * and is deleted only after input_free_polled_device()
|
|
+ * has been invoked. This is needed to ease task of freeing
|
|
+ * sparse keymaps.
|
|
+ */
|
|
+ input_get_device(input);
|
|
+
|
|
+ if (dev->devres_managed) {
|
|
+ dev_dbg(input->dev.parent, "%s: registering %s with devres.\n",
|
|
+ __func__, dev_name(&input->dev));
|
|
+ devres_add(input->dev.parent, devres);
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL(input_register_polled_device);
|
|
+
|
|
+/**
|
|
+ * input_unregister_polled_device - unregister polled device
|
|
+ * @dev: device to unregister
|
|
+ *
|
|
+ * The function unregisters previously registered polled input
|
|
+ * device from input layer. Polling is stopped and device is
|
|
+ * ready to be freed with call to input_free_polled_device().
|
|
+ */
|
|
+void input_unregister_polled_device(struct input_polled_dev *dev)
|
|
+{
|
|
+ if (dev->devres_managed)
|
|
+ WARN_ON(devres_destroy(dev->input->dev.parent,
|
|
+ devm_input_polldev_unregister,
|
|
+ devm_input_polldev_match,
|
|
+ dev));
|
|
+
|
|
+ input_unregister_device(dev->input);
|
|
+}
|
|
+EXPORT_SYMBOL(input_unregister_polled_device);
|
|
diff -rupN linux.orig/drivers/input/joystick/Kconfig linux/drivers/input/joystick/Kconfig
|
|
--- linux.orig/drivers/input/joystick/Kconfig 2022-11-01 17:55:27.006485589 -0400
|
|
+++ linux/drivers/input/joystick/Kconfig 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -392,6 +392,12 @@ config JOYSTICK_FSIA6B
|
|
To compile this driver as a module, choose M here: the
|
|
module will be called fsia6b.
|
|
|
|
+config JOYSTICK_SINGLEADCJOY
|
|
+ tristate "Single SARADC dual-joystick gamepad driver"
|
|
+ select INPUT_POLLDEV
|
|
+ help
|
|
+ The 1-in 4-out SARADC joypad driver.
|
|
+
|
|
config JOYSTICK_N64
|
|
bool "N64 controller"
|
|
depends on MACH_NINTENDO64
|
|
diff -rupN linux.orig/drivers/input/joystick/Makefile linux/drivers/input/joystick/Makefile
|
|
--- linux.orig/drivers/input/joystick/Makefile 2022-11-01 17:55:27.006485589 -0400
|
|
+++ linux/drivers/input/joystick/Makefile 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -30,6 +30,7 @@ obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o
|
|
obj-$(CONFIG_JOYSTICK_QWIIC) += qwiic-joystick.o
|
|
obj-$(CONFIG_JOYSTICK_SENSEHAT) += sensehat-joystick.o
|
|
obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o
|
|
+obj-$(CONFIG_JOYSTICK_SINGLEADCJOY) += singleadcjoy.o
|
|
obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o
|
|
obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o
|
|
obj-$(CONFIG_JOYSTICK_STINGER) += stinger.o
|
|
diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/joystick/singleadcjoy.c
|
|
--- linux.orig/drivers/input/joystick/singleadcjoy.c 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/drivers/input/joystick/singleadcjoy.c 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -0,0 +1,1416 @@
|
|
+/*----------------------------------------------------------------------------*/
|
|
+
|
|
+/*
|
|
+ * Copyright (c) 2008-2021 Anbernic
|
|
+ */
|
|
+
|
|
+/*
|
|
+ * Single SARADC dual-joystick gamepad driver
|
|
+ */
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/slab.h>
|
|
+#include <linux/input.h>
|
|
+#include <linux/input-polldev.h>
|
|
+#include <linux/ioport.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/gpio.h>
|
|
+#include <linux/gpio/consumer.h>
|
|
+#include <linux/gpio_keys.h>
|
|
+#include <linux/iio/consumer.h>
|
|
+#include <linux/iio/types.h>
|
|
+#include <linux/property.h>
|
|
+#include <linux/of_gpio.h>
|
|
+#include <linux/delay.h>
|
|
+#include <linux/pwm.h>
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+#define DRV_NAME "retrogame_joypad"
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+#define ADC_MAX_VOLTAGE 1800
|
|
+#define ADC_DATA_TUNING(x, p) ((x * p) / 100)
|
|
+#define ADC_TUNING_DEFAULT 180
|
|
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
|
+
|
|
+struct bt_adc {
|
|
+ /* report value (mV) */
|
|
+ int value;
|
|
+ /* report type */
|
|
+ int report_type;
|
|
+ /* input device init value (mV) */
|
|
+ int max, min;
|
|
+ /* calibrated adc value */
|
|
+ int cal;
|
|
+ /* adc scale value */
|
|
+ int scale;
|
|
+ /* invert report */
|
|
+ bool invert;
|
|
+ /* amux channel */
|
|
+ int amux_ch;
|
|
+ /* adc data tuning value([percent), p = positive, n = negative */
|
|
+ int tuning_p, tuning_n;
|
|
+};
|
|
+
|
|
+struct analog_mux {
|
|
+ /* IIO ADC Channel : amux connect channel */
|
|
+ struct iio_channel *iio_ch;
|
|
+ /* analog mux select(a,b) gpio */
|
|
+ int sel_a_gpio, sel_b_gpio;
|
|
+ /* analog mux enable gpio */
|
|
+ int en_gpio;
|
|
+};
|
|
+
|
|
+struct bt_gpio {
|
|
+ /* GPIO Request label */
|
|
+ const char *label;
|
|
+ /* GPIO Number */
|
|
+ int num;
|
|
+ /* report type */
|
|
+ int report_type;
|
|
+ /* report linux code */
|
|
+ int linux_code;
|
|
+ /* prev button value */
|
|
+ bool old_value;
|
|
+ /* button press level */
|
|
+ bool active_level;
|
|
+};
|
|
+
|
|
+struct joypad {
|
|
+ struct device *dev;
|
|
+ int poll_interval;
|
|
+
|
|
+ /* report enable/disable */
|
|
+ bool enable;
|
|
+
|
|
+ /* analog mux & joystick control */
|
|
+ struct analog_mux *amux;
|
|
+ /* analog mux max count */
|
|
+ int amux_count;
|
|
+ /* analog button */
|
|
+ struct bt_adc *adcs;
|
|
+
|
|
+ /* report reference point */
|
|
+ bool invert_absx;
|
|
+ bool invert_absy;
|
|
+ bool invert_absrx;
|
|
+ bool invert_absry;
|
|
+
|
|
+ /* report interval (ms) */
|
|
+ int bt_gpio_count;
|
|
+ struct bt_gpio *gpios;
|
|
+
|
|
+ /* button auto repeat */
|
|
+ int auto_repeat;
|
|
+
|
|
+ /* report threshold (mV) */
|
|
+ int bt_adc_fuzz, bt_adc_flat;
|
|
+ /* adc read value scale */
|
|
+ int bt_adc_scale;
|
|
+ /* joystick deadzone control */
|
|
+ int bt_adc_deadzone;
|
|
+
|
|
+ struct mutex lock;
|
|
+
|
|
+ /* amux debug channel */
|
|
+ int debug_ch;
|
|
+
|
|
+ /* pwm device for rumble*/
|
|
+ struct input_dev *input;
|
|
+ struct pwm_device *pwm;
|
|
+ struct work_struct play_work;
|
|
+ u16 level;
|
|
+ u16 boost_weak;
|
|
+ u16 boost_strong;
|
|
+};
|
|
+
|
|
+static int pwm_vibrator_start(struct joypad *joypad)
|
|
+{
|
|
+ struct device *pdev = joypad->input->dev.parent;
|
|
+ struct pwm_state state;
|
|
+ int err;
|
|
+
|
|
+ pwm_get_state(joypad->pwm, &state);
|
|
+ pwm_set_relative_duty_cycle(&state, joypad->level, 0xffff);
|
|
+ state.enabled = true;
|
|
+
|
|
+ err = pwm_apply_state(joypad->pwm, &state);
|
|
+ if (err) {
|
|
+ dev_err(pdev, "failed to apply pwm state: %d", err);
|
|
+ return err;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void pwm_vibrator_stop(struct joypad *joypad)
|
|
+{
|
|
+ pwm_disable(joypad->pwm);
|
|
+}
|
|
+
|
|
+static void pwm_vibrator_play_work(struct work_struct *work)
|
|
+{
|
|
+ struct joypad *joypad = container_of(work,
|
|
+ struct joypad, play_work);
|
|
+
|
|
+ if (joypad->level)
|
|
+ pwm_vibrator_start(joypad);
|
|
+ else
|
|
+ pwm_vibrator_stop(joypad);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+//
|
|
+// set to the value in the boot.ini file. (if exist)
|
|
+//
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static unsigned int g_button_adc_fuzz = 0;
|
|
+static unsigned int g_button_adc_flat = 0;
|
|
+static unsigned int g_button_adc_scale = 0;
|
|
+static unsigned int g_button_adc_deadzone = 0;
|
|
+
|
|
+static int button_adc_fuzz(char *str)
|
|
+{
|
|
+ if (!str)
|
|
+ return -EINVAL;
|
|
+ g_button_adc_fuzz = simple_strtoul(str, NULL, 10);
|
|
+ return 0;
|
|
+}
|
|
+__setup("button-adc-fuzz=", button_adc_fuzz);
|
|
+
|
|
+static int button_adc_flat(char *str)
|
|
+{
|
|
+ if (!str)
|
|
+ return -EINVAL;
|
|
+ g_button_adc_flat = simple_strtoul(str, NULL, 10);
|
|
+ return 0;
|
|
+}
|
|
+__setup("button-adc-flat=", button_adc_flat);
|
|
+
|
|
+static int button_adc_scale(char *str)
|
|
+{
|
|
+ if (!str)
|
|
+ return -EINVAL;
|
|
+ g_button_adc_scale = simple_strtoul(str, NULL, 10);
|
|
+ return 0;
|
|
+}
|
|
+__setup("button-adc-scale=", button_adc_scale);
|
|
+
|
|
+static int button_adc_deadzone(char *str)
|
|
+{
|
|
+ if (!str)
|
|
+ return -EINVAL;
|
|
+ g_button_adc_deadzone = simple_strtoul(str, NULL, 10);
|
|
+ return 0;
|
|
+}
|
|
+__setup("button-adc-deadzone=", button_adc_deadzone);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_amux_select(struct analog_mux *amux, int channel)
|
|
+{
|
|
+ /* select mux channel */
|
|
+ gpio_set_value(amux->en_gpio, 0);
|
|
+
|
|
+ switch(channel) {
|
|
+ case 0: /* EVENT (ABS_RY) */
|
|
+ gpio_set_value(amux->sel_a_gpio, 0);
|
|
+ gpio_set_value(amux->sel_b_gpio, 0);
|
|
+ break;
|
|
+ case 1: /* EVENT (ABS_RX) */
|
|
+ gpio_set_value(amux->sel_a_gpio, 0);
|
|
+ gpio_set_value(amux->sel_b_gpio, 1);
|
|
+ break;
|
|
+ case 2: /* EVENT (ABS_Y) */
|
|
+ gpio_set_value(amux->sel_a_gpio, 1);
|
|
+ gpio_set_value(amux->sel_b_gpio, 0);
|
|
+ break;
|
|
+ case 3: /* EVENT (ABS_X) */
|
|
+ gpio_set_value(amux->sel_a_gpio, 1);
|
|
+ gpio_set_value(amux->sel_b_gpio, 1);
|
|
+ break;
|
|
+ default:
|
|
+ /* amux disanle */
|
|
+ gpio_set_value(amux->en_gpio, 1);
|
|
+ return -1;
|
|
+ }
|
|
+ /* mux swtiching speed : 35ns(on) / 9ns(off) */
|
|
+ usleep_range(10, 20);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_adc_read(struct analog_mux *amux, struct bt_adc *adc)
|
|
+{
|
|
+ int value;
|
|
+
|
|
+
|
|
+ if (joypad_amux_select(amux, adc->amux_ch))
|
|
+ return 0;
|
|
+
|
|
+ iio_read_channel_raw(amux->iio_ch, &value);
|
|
+
|
|
+ value *= adc->scale;
|
|
+
|
|
+ return value;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/poll_interval [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_poll_interval(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->poll_interval = simple_strtoul(buf, NULL, 10);
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_poll_interval(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->poll_interval);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(poll_interval, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_poll_interval,
|
|
+ joypad_store_poll_interval);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/adc_fuzz [r]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_adc_fuzz(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->bt_adc_fuzz);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(adc_fuzz, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_adc_fuzz,
|
|
+ NULL);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/adc_flat [r]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_adc_flat(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->bt_adc_flat);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(adc_flat, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_adc_flat,
|
|
+ NULL);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/enable [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_enable(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->enable = simple_strtoul(buf, NULL, 10);
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_enable(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->enable);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(enable, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_enable,
|
|
+ joypad_store_enable);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/adc_cal [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_adc_cal(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+ bool calibration;
|
|
+
|
|
+ calibration = simple_strtoul(buf, NULL, 10);
|
|
+
|
|
+ if (calibration) {
|
|
+ int nbtn;
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ for (nbtn = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+
|
|
+ adc->value = joypad_adc_read(joypad->amux, adc);
|
|
+ if (!adc->value) {
|
|
+ dev_err(joypad->dev, "%s : saradc channels[%d]!\n",
|
|
+ __func__, nbtn);
|
|
+ continue;
|
|
+ }
|
|
+ adc->cal = adc->value;
|
|
+ }
|
|
+ mutex_unlock(&joypad->lock);
|
|
+ }
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_adc_cal(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+ int nbtn;
|
|
+ ssize_t pos;
|
|
+
|
|
+ for (nbtn = 0, pos = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+ pos += sprintf(&buf[pos], "adc[%d]->cal = %d\n",
|
|
+ nbtn, adc->cal);
|
|
+ }
|
|
+ pos += sprintf(&buf[pos], "adc scale = %d\n", joypad->bt_adc_scale);
|
|
+ return pos;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(adc_cal, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_adc_cal,
|
|
+ joypad_store_adc_cal);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/retrogame_joypad/amux_debug [rw]
|
|
+ *
|
|
+ * echo [debug channel] > amux_debug
|
|
+ * cat amux_debug : debug channel mux set & adc read
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_amux_debug(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ joypad->debug_ch = simple_strtoul(buf, NULL, 10);
|
|
+
|
|
+ /* if error than default setting(debug_ch = 0) */
|
|
+ if (joypad->debug_ch > joypad->amux_count)
|
|
+ joypad->debug_ch = 0;
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_amux_debug(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+ struct analog_mux *amux = joypad->amux;
|
|
+ ssize_t pos;
|
|
+ int value;
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+
|
|
+ /* disable poll driver */
|
|
+ if (joypad->enable)
|
|
+ joypad->enable = false;
|
|
+
|
|
+ if (joypad_amux_select(amux, joypad->debug_ch))
|
|
+ goto err_out;
|
|
+
|
|
+ if (iio_read_channel_processed(amux->iio_ch, &value))
|
|
+ goto err_out;
|
|
+
|
|
+ pos = sprintf(buf, "amux ch[%d], adc scale = %d, adc value = %d\n",
|
|
+ joypad->debug_ch, joypad->bt_adc_scale,
|
|
+ value * joypad->bt_adc_scale);
|
|
+ goto out;
|
|
+
|
|
+err_out:
|
|
+ pos = sprintf(buf, "error : amux setup & adc read!\n");
|
|
+out:
|
|
+ mutex_unlock(&joypad->lock);
|
|
+ return pos;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(amux_debug, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_amux_debug,
|
|
+ joypad_store_amux_debug);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/odroidgo2_joypad/rumble_period [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_period(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ pwm_set_period(joypad->pwm, simple_strtoul(buf, NULL, 21));
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_period(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", pwm_get_period(joypad->pwm));
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(rumble_period, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_period,
|
|
+ joypad_store_period);
|
|
+
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/odroidgo2_joypad/rumble_boost_strong [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_boost_strong(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->boost_strong = simple_strtoul(buf, NULL, 10);
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_boost_strong(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->boost_strong);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(rumble_boost_strong, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_boost_strong,
|
|
+ joypad_store_boost_strong);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/odroidgo2_joypad/rumble_boost_weak [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_boost_weak(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->boost_weak = simple_strtoul(buf, NULL, 10);
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_boost_weak(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ return sprintf(buf, "%d\n", joypad->boost_weak);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(rumble_boost_weak, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_boost_weak,
|
|
+ joypad_store_boost_weak);
|
|
+
|
|
+#define __HDMI__
|
|
+
|
|
+#ifdef __HDMI__
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*
|
|
+ * ATTRIBUTES:
|
|
+ *
|
|
+ * /sys/devices/platform/singleadc-joypad/hdst [rw]
|
|
+ */
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_store_hdst(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ const char *buf,
|
|
+ size_t count)
|
|
+{
|
|
+ return count;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static ssize_t joypad_show_hdst(struct device *dev,
|
|
+ struct device_attribute *attr,
|
|
+ char *buf)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+ //int stcon;
|
|
+ ssize_t pos=0;
|
|
+ if(gpio_get_value(54)==1)
|
|
+ {
|
|
+ pos += sprintf(&buf[pos], "disconnected\n");
|
|
+ }else{
|
|
+ pos += sprintf(&buf[pos], "connected\n");
|
|
+ }
|
|
+ return pos;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static DEVICE_ATTR(hdst, S_IWUSR | S_IRUGO,
|
|
+ joypad_show_hdst,
|
|
+ joypad_store_hdst);
|
|
+#endif
|
|
+
|
|
+#ifdef __HDMI__
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static struct attribute *joypad_attrs[] = {
|
|
+ &dev_attr_poll_interval.attr,
|
|
+ &dev_attr_adc_fuzz.attr,
|
|
+ &dev_attr_adc_flat.attr,
|
|
+ &dev_attr_enable.attr,
|
|
+ &dev_attr_adc_cal.attr,
|
|
+ &dev_attr_amux_debug.attr,
|
|
+ &dev_attr_hdst.attr,
|
|
+ &dev_attr_rumble_period.attr,
|
|
+ &dev_attr_rumble_boost_strong.attr,
|
|
+ &dev_attr_rumble_boost_weak.attr,
|
|
+ NULL,
|
|
+};
|
|
+#else
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static struct attribute *joypad_attrs[] = {
|
|
+ &dev_attr_poll_interval.attr,
|
|
+ &dev_attr_adc_fuzz.attr,
|
|
+ &dev_attr_adc_flat.attr,
|
|
+ &dev_attr_enable.attr,
|
|
+ &dev_attr_adc_cal.attr,
|
|
+ &dev_attr_amux_debug.attr,
|
|
+ &dev_attr_rumble_period.attr,
|
|
+ &dev_attr_rumble_boost_strong.attr,
|
|
+ &dev_attr_rumble_boost_weak.attr,
|
|
+ NULL,
|
|
+};
|
|
+#endif
|
|
+static struct attribute_group joypad_attr_group = {
|
|
+ .attrs = joypad_attrs,
|
|
+};
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_gpio_check(struct input_polled_dev *poll_dev)
|
|
+{
|
|
+ struct joypad *joypad = poll_dev->private;
|
|
+ int nbtn, value;
|
|
+
|
|
+ for (nbtn = 0; nbtn < joypad->bt_gpio_count; nbtn++) {
|
|
+ struct bt_gpio *gpio = &joypad->gpios[nbtn];
|
|
+
|
|
+ if (gpio_get_value_cansleep(gpio->num) < 0) {
|
|
+ dev_err(joypad->dev, "failed to get gpio state\n");
|
|
+ continue;
|
|
+ }
|
|
+ value = gpio_get_value(gpio->num);
|
|
+ if (value != gpio->old_value) {
|
|
+ input_event(poll_dev->input,
|
|
+ gpio->report_type,
|
|
+ gpio->linux_code,
|
|
+ (value == gpio->active_level) ? 1 : 0);
|
|
+ gpio->old_value = value;
|
|
+ }
|
|
+ }
|
|
+ input_sync(poll_dev->input);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_adc_check(struct input_polled_dev *poll_dev)
|
|
+{
|
|
+ struct joypad *joypad = poll_dev->private;
|
|
+ int nbtn;
|
|
+
|
|
+ for (nbtn = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+
|
|
+ adc->value = joypad_adc_read(joypad->amux, adc);
|
|
+ if (!adc->value) {
|
|
+ //dev_err(joypad->dev, "%s : saradc channels[%d]! adc->value : %d\n",__func__, nbtn, adc->value);
|
|
+ continue;
|
|
+ }
|
|
+ adc->value = adc->value - adc->cal;
|
|
+
|
|
+ /* Joystick Deadzone check */
|
|
+ if (joypad->bt_adc_deadzone) {
|
|
+ if (abs(adc->value) < joypad->bt_adc_deadzone)
|
|
+ adc->value = 0;
|
|
+ }
|
|
+
|
|
+ /* adc data tuning */
|
|
+ if (adc->tuning_n && adc->value < 0)
|
|
+ adc->value = ADC_DATA_TUNING(adc->value, adc->tuning_n);
|
|
+ if (adc->tuning_p && adc->value > 0)
|
|
+ adc->value = ADC_DATA_TUNING(adc->value, adc->tuning_p);
|
|
+
|
|
+ adc->value = adc->value > adc->max ? adc->max : adc->value;
|
|
+ adc->value = adc->value < adc->min ? adc->min : adc->value;
|
|
+
|
|
+ input_report_abs(poll_dev->input,
|
|
+ adc->report_type,
|
|
+ adc->invert ? adc->value * (-1) : adc->value);
|
|
+ }
|
|
+ input_sync(poll_dev->input);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_poll(struct input_polled_dev *poll_dev)
|
|
+{
|
|
+ struct joypad *joypad = poll_dev->private;
|
|
+
|
|
+ if (joypad->enable) {
|
|
+ joypad_adc_check(poll_dev);
|
|
+ joypad_gpio_check(poll_dev);
|
|
+ }
|
|
+ if (poll_dev->poll_interval != joypad->poll_interval) {
|
|
+ mutex_lock(&joypad->lock);
|
|
+ poll_dev->poll_interval = joypad->poll_interval;
|
|
+ mutex_unlock(&joypad->lock);
|
|
+ }
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_open(struct input_polled_dev *poll_dev)
|
|
+{
|
|
+ struct joypad *joypad = poll_dev->private;
|
|
+ int nbtn;
|
|
+
|
|
+ for (nbtn = 0; nbtn < joypad->bt_gpio_count; nbtn++) {
|
|
+ struct bt_gpio *gpio = &joypad->gpios[nbtn];
|
|
+ gpio->old_value = gpio->active_level ? 0 : 1;
|
|
+ }
|
|
+ for (nbtn = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+
|
|
+ adc->value = joypad_adc_read(joypad->amux, adc);
|
|
+ if (!adc->value) {
|
|
+ dev_err(joypad->dev, "%s : saradc channels[%d]!\n",
|
|
+ __func__, nbtn);
|
|
+ continue;
|
|
+ }
|
|
+ adc->cal = adc->value;
|
|
+ dev_info(joypad->dev, "%s : adc[%d] adc->cal = %d\n",
|
|
+ __func__, nbtn, adc->cal);
|
|
+ }
|
|
+ /* buttons status sync */
|
|
+ joypad_adc_check(poll_dev);
|
|
+ joypad_gpio_check(poll_dev);
|
|
+
|
|
+ /* button report enable */
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->enable = true;
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ dev_info(joypad->dev, "%s : opened\n", __func__);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_close(struct input_polled_dev *poll_dev)
|
|
+{
|
|
+ struct joypad *joypad = poll_dev->private;
|
|
+
|
|
+ /* button report disable */
|
|
+ mutex_lock(&joypad->lock);
|
|
+ joypad->enable = false;
|
|
+ mutex_unlock(&joypad->lock);
|
|
+
|
|
+ cancel_work_sync(&joypad->play_work);
|
|
+ pwm_vibrator_stop(joypad);
|
|
+
|
|
+ dev_info(joypad->dev, "%s : closed\n", __func__);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_amux_setup(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ struct analog_mux *amux;
|
|
+ enum iio_chan_type type;
|
|
+ enum of_gpio_flags flags;
|
|
+ int ret;
|
|
+
|
|
+ /* analog mux control struct init */
|
|
+ joypad->amux = devm_kzalloc(dev, sizeof(struct analog_mux),
|
|
+ GFP_KERNEL);
|
|
+ if (!joypad->amux) {
|
|
+ dev_err(dev, "%s amux devm_kzmalloc error!", __func__);
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+ amux = joypad->amux;
|
|
+ amux->iio_ch = devm_iio_channel_get(dev, "amux_adc");
|
|
+ if (IS_ERR(amux->iio_ch)) {
|
|
+ dev_err(dev, "iio channel get error\n");
|
|
+ return -EINVAL;
|
|
+ }
|
|
+ if (!amux->iio_ch->indio_dev)
|
|
+ return -ENXIO;
|
|
+
|
|
+ if (iio_get_channel_type(amux->iio_ch, &type))
|
|
+ return -EINVAL;
|
|
+
|
|
+ if (type != IIO_VOLTAGE) {
|
|
+ dev_err(dev, "Incompatible channel type %d\n", type);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ amux->sel_a_gpio = of_get_named_gpio_flags(dev->of_node,
|
|
+ "amux-a-gpios", 0, &flags);
|
|
+ if (gpio_is_valid(amux->sel_a_gpio)) {
|
|
+ ret = devm_gpio_request(dev, amux->sel_a_gpio, "amux-sel-a");
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "%s : failed to request amux-sel-a %d\n",
|
|
+ __func__, amux->sel_a_gpio);
|
|
+ goto err_out;
|
|
+ }
|
|
+ ret = gpio_direction_output(amux->sel_a_gpio, 0);
|
|
+ if (ret < 0)
|
|
+ goto err_out;
|
|
+ }
|
|
+
|
|
+ amux->sel_b_gpio = of_get_named_gpio_flags(dev->of_node,
|
|
+ "amux-b-gpios", 0, &flags);
|
|
+ if (gpio_is_valid(amux->sel_b_gpio)) {
|
|
+ ret = devm_gpio_request(dev, amux->sel_b_gpio, "amux-sel-b");
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "%s : failed to request amux-sel-b %d\n",
|
|
+ __func__, amux->sel_b_gpio);
|
|
+ goto err_out;
|
|
+ }
|
|
+ ret = gpio_direction_output(amux->sel_b_gpio, 0);
|
|
+ if (ret < 0)
|
|
+ goto err_out;
|
|
+ }
|
|
+
|
|
+ amux->en_gpio = of_get_named_gpio_flags(dev->of_node,
|
|
+ "amux-en-gpios", 0, &flags);
|
|
+ if (gpio_is_valid(amux->en_gpio)) {
|
|
+ ret = devm_gpio_request(dev, amux->en_gpio, "amux-en");
|
|
+ if (ret < 0) {
|
|
+ dev_err(dev, "%s : failed to request amux-en %d\n",
|
|
+ __func__, amux->en_gpio);
|
|
+ goto err_out;
|
|
+ }
|
|
+ ret = gpio_direction_output(amux->en_gpio, 0);
|
|
+ if (ret < 0)
|
|
+ goto err_out;
|
|
+ }
|
|
+ return 0;
|
|
+err_out:
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_adc_setup(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ int nbtn;
|
|
+
|
|
+ /* adc button struct init */
|
|
+ joypad->adcs = devm_kzalloc(dev, joypad->amux_count *
|
|
+ sizeof(struct bt_adc), GFP_KERNEL);
|
|
+ if (!joypad->adcs) {
|
|
+ dev_err(dev, "%s devm_kzmalloc error!", __func__);
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ for (nbtn = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+
|
|
+ adc->scale = joypad->bt_adc_scale;
|
|
+
|
|
+ adc->max = (ADC_MAX_VOLTAGE / 2);
|
|
+ adc->min = (ADC_MAX_VOLTAGE / 2) * (-1);
|
|
+ if (adc->scale) {
|
|
+ adc->max *= adc->scale;
|
|
+ adc->min *= adc->scale;
|
|
+ }
|
|
+ adc->amux_ch = nbtn;
|
|
+ adc->invert = false;
|
|
+
|
|
+ switch (nbtn) {
|
|
+ case 0:
|
|
+ if (joypad->invert_absry)
|
|
+ adc->invert = true;
|
|
+ adc->report_type = ABS_RY;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_ry-p-tuning",
|
|
+ &adc->tuning_p))
|
|
+ adc->tuning_p = ADC_TUNING_DEFAULT;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_ry-n-tuning",
|
|
+ &adc->tuning_n))
|
|
+ adc->tuning_n = ADC_TUNING_DEFAULT;
|
|
+ break;
|
|
+ case 1:
|
|
+ if (joypad->invert_absrx)
|
|
+ adc->invert = true;
|
|
+ adc->report_type = ABS_RX;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_rx-p-tuning",
|
|
+ &adc->tuning_p))
|
|
+ adc->tuning_p = ADC_TUNING_DEFAULT;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_rx-n-tuning",
|
|
+ &adc->tuning_n))
|
|
+ adc->tuning_n = ADC_TUNING_DEFAULT;
|
|
+ break;
|
|
+ case 2:
|
|
+ if (joypad->invert_absy)
|
|
+ adc->invert = true;
|
|
+ adc->report_type = ABS_Y;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_y-p-tuning",
|
|
+ &adc->tuning_p))
|
|
+ adc->tuning_p = ADC_TUNING_DEFAULT;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_y-n-tuning",
|
|
+ &adc->tuning_n))
|
|
+ adc->tuning_n = ADC_TUNING_DEFAULT;
|
|
+ break;
|
|
+ case 3:
|
|
+ if (joypad->invert_absx)
|
|
+ adc->invert = true;
|
|
+ adc->report_type = ABS_X;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_x-p-tuning",
|
|
+ &adc->tuning_p))
|
|
+ adc->tuning_p = ADC_TUNING_DEFAULT;
|
|
+ if (device_property_read_u32(dev,
|
|
+ "abs_x-n-tuning",
|
|
+ &adc->tuning_n))
|
|
+ adc->tuning_n = ADC_TUNING_DEFAULT;
|
|
+ break;
|
|
+ default :
|
|
+ dev_err(dev, "%s amux count(%d) error!",
|
|
+ __func__, nbtn);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_gpio_setup(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ struct device_node *node, *pp;
|
|
+ int nbtn;
|
|
+
|
|
+ node = dev->of_node;
|
|
+ if (!node)
|
|
+ return -ENODEV;
|
|
+
|
|
+ joypad->gpios = devm_kzalloc(dev, joypad->bt_gpio_count *
|
|
+ sizeof(struct bt_gpio), GFP_KERNEL);
|
|
+
|
|
+ if (!joypad->gpios) {
|
|
+ dev_err(dev, "%s devm_kzmalloc error!", __func__);
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ nbtn = 0;
|
|
+ for_each_child_of_node(node, pp) {
|
|
+ enum of_gpio_flags flags;
|
|
+ struct bt_gpio *gpio = &joypad->gpios[nbtn++];
|
|
+ int error;
|
|
+
|
|
+ gpio->num = of_get_gpio_flags(pp, 0, &flags);
|
|
+ if (gpio->num < 0) {
|
|
+ error = gpio->num;
|
|
+ dev_err(dev, "Failed to get gpio flags, error: %d\n",
|
|
+ error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ /* gpio active level(key press level) */
|
|
+ gpio->active_level = (flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
|
|
+
|
|
+ gpio->label = of_get_property(pp, "label", NULL);
|
|
+
|
|
+ if (gpio_is_valid(gpio->num)) {
|
|
+ error = devm_gpio_request_one(dev, gpio->num,
|
|
+ GPIOF_IN, gpio->label);
|
|
+ if (error < 0) {
|
|
+ dev_err(dev,
|
|
+ "Failed to request GPIO %d, error %d\n",
|
|
+ gpio->num, error);
|
|
+ return error;
|
|
+ }
|
|
+ }
|
|
+ if (of_property_read_u32(pp, "linux,code", &gpio->linux_code)) {
|
|
+ dev_err(dev, "Button without keycode: 0x%x\n",
|
|
+ gpio->num);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+ if (of_property_read_u32(pp, "linux,input-type",
|
|
+ &gpio->report_type))
|
|
+ gpio->report_type = EV_KEY;
|
|
+ }
|
|
+ if (nbtn == 0)
|
|
+ return -EINVAL;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+struct input_dev * joypad_input_g;
|
|
+
|
|
+
|
|
+void rk_send_key_f_key_up(void)
|
|
+{
|
|
+ if (!joypad_input_g)
|
|
+ return;
|
|
+
|
|
+ input_report_key(joypad_input_g, BTN_MODE, 1);
|
|
+ input_sync(joypad_input_g);
|
|
+}
|
|
+EXPORT_SYMBOL(rk_send_key_f_key_up);
|
|
+
|
|
+
|
|
+void rk_send_key_f_key_down(void)
|
|
+{
|
|
+ if (!joypad_input_g)
|
|
+ return;
|
|
+
|
|
+ input_report_key(joypad_input_g, BTN_MODE, 0);
|
|
+ input_sync(joypad_input_g);
|
|
+}
|
|
+EXPORT_SYMBOL(rk_send_key_f_key_down);
|
|
+
|
|
+static int rumble_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
|
|
+{
|
|
+ struct joypad *joypad = data;
|
|
+ u32 boosted_level;
|
|
+ if (effect->type != FF_RUMBLE)
|
|
+ return 0;
|
|
+
|
|
+ if (effect->u.rumble.strong_magnitude)
|
|
+ boosted_level = effect->u.rumble.strong_magnitude + joypad->boost_strong;
|
|
+ else
|
|
+ boosted_level = effect->u.rumble.weak_magnitude + joypad->boost_weak;
|
|
+
|
|
+ joypad->level = (u16)CLAMP(boosted_level, 0, 0xffff);
|
|
+
|
|
+ dev_info(joypad->dev,"joypad->level = %d", joypad->level);
|
|
+ schedule_work(&joypad->play_work);
|
|
+ return 0;
|
|
+}
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_rumble_setup(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ int err;
|
|
+ struct pwm_state state;
|
|
+
|
|
+ joypad->pwm = devm_pwm_get(dev, "enable");
|
|
+ if (IS_ERR(joypad->pwm))
|
|
+ {
|
|
+ dev_err(dev, "rumble get error\n");
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ INIT_WORK(&joypad->play_work, pwm_vibrator_play_work);
|
|
+
|
|
+ /* Sync up PWM state and ensure it is off. */
|
|
+ pwm_init_state(joypad->pwm, &state);
|
|
+ state.enabled = false;
|
|
+ err = pwm_apply_state(joypad->pwm, &state);
|
|
+ if (err) {
|
|
+ dev_err(dev, "failed to apply initial PWM state: %d",
|
|
+ err);
|
|
+ return err;
|
|
+ }
|
|
+ dev_info(dev, "rumble setup success!\n");
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int joypad_input_setup(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ struct input_polled_dev *poll_dev;
|
|
+ struct input_dev *input;
|
|
+ int nbtn, error;
|
|
+ u32 joypad_revision = 0;
|
|
+ u32 joypad_product = 0;
|
|
+ u32 boost_weak = 0;
|
|
+ u32 boost_strong = 0;
|
|
+ poll_dev = devm_input_allocate_polled_device(dev);
|
|
+ if (!poll_dev) {
|
|
+ dev_err(dev, "no memory for polled device\n");
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ poll_dev->private = joypad;
|
|
+ poll_dev->poll = joypad_poll;
|
|
+ poll_dev->poll_interval = joypad->poll_interval;
|
|
+ poll_dev->open = joypad_open;
|
|
+ poll_dev->close = joypad_close;
|
|
+
|
|
+ input = poll_dev->input;
|
|
+ joypad->input = poll_dev->input;
|
|
+
|
|
+ device_property_read_string(dev, "joypad-name", &input->name);
|
|
+ input->phys = DRV_NAME"/input0";
|
|
+
|
|
+ device_property_read_u32(dev, "joypad-revision", &joypad_revision);
|
|
+ device_property_read_u32(dev, "joypad-product", &joypad_product);
|
|
+ input->id.bustype = BUS_HOST;
|
|
+ input->id.vendor = 0x484B;
|
|
+ input->id.product = (u16)joypad_product;
|
|
+ input->id.version = (u16)joypad_revision;
|
|
+
|
|
+ /* IIO ADC key setup (0 mv ~ 1800 mv) * adc->scale */
|
|
+ __set_bit(EV_ABS, input->evbit);
|
|
+ for(nbtn = 0; nbtn < joypad->amux_count; nbtn++) {
|
|
+ struct bt_adc *adc = &joypad->adcs[nbtn];
|
|
+ input_set_abs_params(input, adc->report_type,
|
|
+ adc->min, adc->max,
|
|
+ joypad->bt_adc_fuzz,
|
|
+ joypad->bt_adc_flat);
|
|
+ dev_info(dev,
|
|
+ "%s : SCALE = %d, ABS min = %d, max = %d,"
|
|
+ " fuzz = %d, flat = %d, deadzone = %d\n",
|
|
+ __func__, adc->scale, adc->min, adc->max,
|
|
+ joypad->bt_adc_fuzz, joypad->bt_adc_flat,
|
|
+ joypad->bt_adc_deadzone);
|
|
+ dev_info(dev,
|
|
+ "%s : adc tuning_p = %d, adc_tuning_n = %d\n\n",
|
|
+ __func__, adc->tuning_p, adc->tuning_n);
|
|
+ }
|
|
+
|
|
+ /* Rumble setip*/
|
|
+ device_property_read_u32(dev, "rumble-boost-weak", &boost_weak);
|
|
+ device_property_read_u32(dev, "rumble-boost-strong", &boost_strong);
|
|
+ joypad->boost_weak = boost_weak;
|
|
+ joypad->boost_strong = boost_strong;
|
|
+ dev_info(dev, "Boost = %d, %d",boost_weak, boost_strong);
|
|
+ input_set_capability(input, EV_FF, FF_RUMBLE);
|
|
+ error = input_ff_create_memless(input, joypad, rumble_play_effect);
|
|
+ if (error) {
|
|
+ dev_err(dev, "unable to register rumble, err=%d\n",
|
|
+ error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+
|
|
+ /* GPIO key setup */
|
|
+ __set_bit(EV_KEY, input->evbit);
|
|
+ for(nbtn = 0; nbtn < joypad->bt_gpio_count; nbtn++) {
|
|
+ struct bt_gpio *gpio = &joypad->gpios[nbtn];
|
|
+ input_set_capability(input, gpio->report_type,
|
|
+ gpio->linux_code);
|
|
+ }
|
|
+
|
|
+ if (joypad->auto_repeat)
|
|
+ __set_bit(EV_REP, input->evbit);
|
|
+
|
|
+ joypad->dev = dev;
|
|
+
|
|
+ error = input_register_polled_device(poll_dev);
|
|
+ if (error) {
|
|
+ dev_err(dev, "unable to register polled device, err=%d\n",
|
|
+ error);
|
|
+ return error;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void joypad_setup_value_check(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ /*
|
|
+ fuzz: specifies fuzz value that is used to filter noise from
|
|
+ the event stream.
|
|
+ */
|
|
+ if (g_button_adc_fuzz)
|
|
+ joypad->bt_adc_fuzz = g_button_adc_fuzz;
|
|
+ else
|
|
+ device_property_read_u32(dev, "button-adc-fuzz",
|
|
+ &joypad->bt_adc_fuzz);
|
|
+ /*
|
|
+ flat: values that are within this value will be discarded by
|
|
+ joydev interface and reported as 0 instead.
|
|
+ */
|
|
+ if (g_button_adc_flat)
|
|
+ joypad->bt_adc_flat = g_button_adc_flat;
|
|
+ else
|
|
+ device_property_read_u32(dev, "button-adc-flat",
|
|
+ &joypad->bt_adc_flat);
|
|
+
|
|
+ /* Joystick report value control */
|
|
+ if (g_button_adc_scale)
|
|
+ joypad->bt_adc_scale = g_button_adc_scale;
|
|
+ else
|
|
+ device_property_read_u32(dev, "button-adc-scale",
|
|
+ &joypad->bt_adc_scale);
|
|
+
|
|
+ /* Joystick deadzone value control */
|
|
+ if (g_button_adc_deadzone)
|
|
+ joypad->bt_adc_deadzone = g_button_adc_deadzone;
|
|
+ else
|
|
+ device_property_read_u32(dev, "button-adc-deadzone",
|
|
+ &joypad->bt_adc_deadzone);
|
|
+
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_dt_parse(struct device *dev, struct joypad *joypad)
|
|
+{
|
|
+ int error = 0;
|
|
+
|
|
+ /* initialize value check from boot.ini */
|
|
+ joypad_setup_value_check(dev, joypad);
|
|
+
|
|
+ device_property_read_u32(dev, "amux-count",
|
|
+ &joypad->amux_count);
|
|
+
|
|
+ device_property_read_u32(dev, "poll-interval",
|
|
+ &joypad->poll_interval);
|
|
+
|
|
+ joypad->auto_repeat = device_property_present(dev, "autorepeat");
|
|
+
|
|
+ /* change the report reference point? (ADC MAX - read value) */
|
|
+ joypad->invert_absx = device_property_present(dev, "invert-absx");
|
|
+ joypad->invert_absy = device_property_present(dev, "invert-absy");
|
|
+ joypad->invert_absrx = device_property_present(dev, "invert-absrx");
|
|
+ joypad->invert_absry = device_property_present(dev, "invert-absry");
|
|
+ dev_info(dev, "%s : invert-absx = %d, inveret-absy = %d, invert-absrx = %d, inveret-absry = %d\n",
|
|
+ __func__, joypad->invert_absx, joypad->invert_absy, joypad->invert_absrx, joypad->invert_absry);
|
|
+
|
|
+ joypad->bt_gpio_count = device_get_child_node_count(dev);
|
|
+
|
|
+ if ((joypad->amux_count == 0) || (joypad->bt_gpio_count == 0)) {
|
|
+ dev_err(dev, "adc key = %d, gpio key = %d error!",
|
|
+ joypad->amux_count, joypad->bt_gpio_count);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ error = joypad_adc_setup(dev, joypad);
|
|
+ if (error)
|
|
+ return error;
|
|
+
|
|
+ error = joypad_amux_setup(dev, joypad);
|
|
+ if (error)
|
|
+ return error;
|
|
+
|
|
+ error = joypad_gpio_setup(dev, joypad);
|
|
+ if (error)
|
|
+ return error;
|
|
+
|
|
+ dev_info(dev, "%s : adc key cnt = %d, gpio key cnt = %d\n",
|
|
+ __func__, joypad->amux_count, joypad->bt_gpio_count);
|
|
+
|
|
+ return error;
|
|
+}
|
|
+static int __maybe_unused joypad_suspend(struct device *dev)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ cancel_work_sync(&joypad->play_work);
|
|
+ if (joypad->level)
|
|
+ pwm_vibrator_stop(joypad);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int __maybe_unused joypad_resume(struct device *dev)
|
|
+{
|
|
+ struct platform_device *pdev = to_platform_device(dev);
|
|
+ struct joypad *joypad = platform_get_drvdata(pdev);
|
|
+
|
|
+ if (joypad->level)
|
|
+ pwm_vibrator_start(joypad);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static SIMPLE_DEV_PM_OPS(joypad_pm_ops,
|
|
+ joypad_suspend, joypad_resume);
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int joypad_probe(struct platform_device *pdev)
|
|
+{
|
|
+ struct joypad *joypad;
|
|
+ struct device *dev = &pdev->dev;
|
|
+ int error;
|
|
+
|
|
+ joypad = devm_kzalloc(dev, sizeof(struct joypad), GFP_KERNEL);
|
|
+ if (!joypad) {
|
|
+ dev_err(dev, "joypad devm_kzmalloc error!");
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ /* device tree data parse */
|
|
+ error = joypad_dt_parse(dev, joypad);
|
|
+ if (error) {
|
|
+ dev_err(dev, "dt parse error!(err = %d)\n", error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ mutex_init(&joypad->lock);
|
|
+ platform_set_drvdata(pdev, joypad);
|
|
+
|
|
+ error = sysfs_create_group(&pdev->dev.kobj, &joypad_attr_group);
|
|
+ if (error) {
|
|
+ dev_err(dev, "create sysfs group fail, error: %d\n",
|
|
+ error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ /* poll input device setup */
|
|
+ error = joypad_input_setup(dev, joypad);
|
|
+ if (error) {
|
|
+ dev_err(dev, "input setup failed!(err = %d)\n", error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ /* rumble setup */
|
|
+ error = joypad_rumble_setup(dev, joypad);
|
|
+ if (error) {
|
|
+ dev_err(dev, "rumble setup failed!(err = %d)\n", error);
|
|
+ return error;
|
|
+ }
|
|
+
|
|
+ dev_info(dev, "%s : probe success\n", __func__);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static const struct of_device_id joypad_of_match[] = {
|
|
+ { .compatible = "singleadc-joypad", },
|
|
+ {},
|
|
+};
|
|
+
|
|
+MODULE_DEVICE_TABLE(of, joypad_of_match);
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static struct platform_driver joypad_driver = {
|
|
+ .probe = joypad_probe,
|
|
+ .driver = {
|
|
+ .name = DRV_NAME,
|
|
+ .pm = &joypad_pm_ops,
|
|
+ .of_match_table = of_match_ptr(joypad_of_match),
|
|
+ },
|
|
+};
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static int __init joypad_init(void)
|
|
+{
|
|
+ return platform_driver_register(&joypad_driver);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+static void __exit joypad_exit(void)
|
|
+{
|
|
+ platform_driver_unregister(&joypad_driver);
|
|
+}
|
|
+
|
|
+/*----------------------------------------------------------------------------*/
|
|
+late_initcall(joypad_init);
|
|
+module_exit(joypad_exit);
|
|
diff -rupN linux.orig/drivers/input/Kconfig linux/drivers/input/Kconfig
|
|
--- linux.orig/drivers/input/Kconfig 2022-11-01 17:55:27.002485730 -0400
|
|
+++ linux/drivers/input/Kconfig 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -51,6 +51,19 @@ config INPUT_FF_MEMLESS
|
|
To compile this driver as a module, choose M here: the
|
|
module will be called ff-memless.
|
|
|
|
+config INPUT_POLLDEV
|
|
+ tristate "Polled input device skeleton"
|
|
+ help
|
|
+ Say Y here if you are using a driver for an input
|
|
+ device that periodically polls hardware state. This
|
|
+ option is only useful for out-of-tree drivers since
|
|
+ in-tree drivers select it automatically.
|
|
+
|
|
+ If unsure, say N.
|
|
+
|
|
+ To compile this driver as a module, choose M here: the
|
|
+ module will be called input-polldev.
|
|
+
|
|
config INPUT_SPARSEKMAP
|
|
tristate "Sparse keymap support library"
|
|
help
|
|
diff -rupN linux.orig/drivers/input/Makefile linux/drivers/input/Makefile
|
|
--- linux.orig/drivers/input/Makefile 2022-11-01 17:55:27.002485730 -0400
|
|
+++ linux/drivers/input/Makefile 2022-11-01 17:56:17.140793505 -0400
|
|
@@ -10,6 +10,7 @@ input-core-y := input.o input-compat.o i
|
|
input-core-y += touchscreen.o
|
|
|
|
obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o
|
|
+obj-$(CONFIG_INPUT_POLLDEV) += input-polldev.o
|
|
obj-$(CONFIG_INPUT_SPARSEKMAP) += sparse-keymap.o
|
|
obj-$(CONFIG_INPUT_MATRIXKMAP) += matrix-keymap.o
|
|
obj-$(CONFIG_INPUT_VIVALDIFMAP) += vivaldi-fmap.o
|
|
--- linux.orig/drivers/power/supply/cw2015_battery.c.orig 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/drivers/power/supply/cw2015_battery.c.orig 2022-10-29 04:08:36.000000000 -0400
|
|
@@ -0,0 +1,764 @@
|
|
+// SPDX-License-Identifier: GPL-2.0
|
|
+/*
|
|
+ * Fuel gauge driver for CellWise 2013 / 2015
|
|
+ *
|
|
+ * Copyright (C) 2012, RockChip
|
|
+ * Copyright (C) 2020, Tobias Schramm
|
|
+ *
|
|
+ * Authors: xuhuicong <xhc@rock-chips.com>
|
|
+ * Authors: Tobias Schramm <t.schramm@manjaro.org>
|
|
+ */
|
|
+
|
|
+#include <linux/bits.h>
|
|
+#include <linux/delay.h>
|
|
+#include <linux/i2c.h>
|
|
+#include <linux/gfp.h>
|
|
+#include <linux/gpio/consumer.h>
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/power_supply.h>
|
|
+#include <linux/property.h>
|
|
+#include <linux/regmap.h>
|
|
+#include <linux/time.h>
|
|
+#include <linux/workqueue.h>
|
|
+
|
|
+#define CW2015_SIZE_BATINFO 64
|
|
+
|
|
+#define CW2015_RESET_TRIES 5
|
|
+
|
|
+#define CW2015_REG_VERSION 0x00
|
|
+#define CW2015_REG_VCELL 0x02
|
|
+#define CW2015_REG_SOC 0x04
|
|
+#define CW2015_REG_RRT_ALERT 0x06
|
|
+#define CW2015_REG_CONFIG 0x08
|
|
+#define CW2015_REG_MODE 0x0A
|
|
+#define CW2015_REG_BATINFO 0x10
|
|
+
|
|
+#define CW2015_MODE_SLEEP_MASK GENMASK(7, 6)
|
|
+#define CW2015_MODE_SLEEP (0x03 << 6)
|
|
+#define CW2015_MODE_NORMAL (0x00 << 6)
|
|
+#define CW2015_MODE_QUICK_START (0x03 << 4)
|
|
+#define CW2015_MODE_RESTART (0x0f << 0)
|
|
+
|
|
+#define CW2015_CONFIG_UPDATE_FLG (0x01 << 1)
|
|
+#define CW2015_ATHD(x) ((x) << 3)
|
|
+#define CW2015_MASK_ATHD GENMASK(7, 3)
|
|
+#define CW2015_MASK_SOC GENMASK(12, 0)
|
|
+
|
|
+/* reset gauge of no valid state of charge could be polled for 40s */
|
|
+#define CW2015_BAT_SOC_ERROR_MS (40 * MSEC_PER_SEC)
|
|
+/* reset gauge if state of charge stuck for half an hour during charging */
|
|
+#define CW2015_BAT_CHARGING_STUCK_MS (1800 * MSEC_PER_SEC)
|
|
+
|
|
+/* poll interval from CellWise GPL Android driver example */
|
|
+#define CW2015_DEFAULT_POLL_INTERVAL_MS 8000
|
|
+
|
|
+#define CW2015_AVERAGING_SAMPLES 3
|
|
+
|
|
+struct cw_battery {
|
|
+ struct device *dev;
|
|
+ struct workqueue_struct *battery_workqueue;
|
|
+ struct delayed_work battery_delay_work;
|
|
+ struct regmap *regmap;
|
|
+ struct power_supply *rk_bat;
|
|
+ struct power_supply_battery_info *battery;
|
|
+ u8 *bat_profile;
|
|
+
|
|
+ bool charger_attached;
|
|
+ bool battery_changed;
|
|
+
|
|
+ int soc;
|
|
+ int voltage_mv;
|
|
+ int status;
|
|
+ int time_to_empty;
|
|
+ int charge_count;
|
|
+
|
|
+ u32 poll_interval_ms;
|
|
+ u8 alert_level;
|
|
+
|
|
+ unsigned int read_errors;
|
|
+ unsigned int charge_stuck_cnt;
|
|
+};
|
|
+
|
|
+static int cw_read_word(struct cw_battery *cw_bat, u8 reg, u16 *val)
|
|
+{
|
|
+ __be16 value;
|
|
+ int ret;
|
|
+
|
|
+ ret = regmap_bulk_read(cw_bat->regmap, reg, &value, sizeof(value));
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ *val = be16_to_cpu(value);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int cw_update_profile(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret;
|
|
+ unsigned int reg_val;
|
|
+ u8 reset_val;
|
|
+
|
|
+ /* make sure gauge is not in sleep mode */
|
|
+ ret = regmap_read(cw_bat->regmap, CW2015_REG_MODE, ®_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ reset_val = reg_val;
|
|
+ if ((reg_val & CW2015_MODE_SLEEP_MASK) == CW2015_MODE_SLEEP) {
|
|
+ dev_err(cw_bat->dev,
|
|
+ "Gauge is in sleep mode, can't update battery info\n");
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ /* write new battery info */
|
|
+ ret = regmap_raw_write(cw_bat->regmap, CW2015_REG_BATINFO,
|
|
+ cw_bat->bat_profile,
|
|
+ CW2015_SIZE_BATINFO);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ /* set config update flag */
|
|
+ reg_val |= CW2015_CONFIG_UPDATE_FLG;
|
|
+ reg_val &= ~CW2015_MASK_ATHD;
|
|
+ reg_val |= CW2015_ATHD(cw_bat->alert_level);
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_CONFIG, reg_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ /* reset gauge to apply new battery profile */
|
|
+ reset_val &= ~CW2015_MODE_RESTART;
|
|
+ reg_val = reset_val | CW2015_MODE_RESTART;
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_MODE, reg_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ /* wait for gauge to reset */
|
|
+ msleep(20);
|
|
+
|
|
+ /* clear reset flag */
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_MODE, reset_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ /* wait for gauge to become ready */
|
|
+ ret = regmap_read_poll_timeout(cw_bat->regmap, CW2015_REG_SOC,
|
|
+ reg_val, reg_val <= 100,
|
|
+ 10 * USEC_PER_MSEC, 10 * USEC_PER_SEC);
|
|
+ if (ret)
|
|
+ dev_err(cw_bat->dev,
|
|
+ "Gauge did not become ready after profile upload\n");
|
|
+ else
|
|
+ dev_dbg(cw_bat->dev, "Battery profile updated\n");
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+static int cw_init(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret;
|
|
+ unsigned int reg_val = CW2015_MODE_SLEEP;
|
|
+
|
|
+ if ((reg_val & CW2015_MODE_SLEEP_MASK) == CW2015_MODE_SLEEP) {
|
|
+ reg_val = CW2015_MODE_NORMAL;
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_MODE, reg_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ ret = regmap_read(cw_bat->regmap, CW2015_REG_CONFIG, ®_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ if ((reg_val & CW2015_MASK_ATHD) != CW2015_ATHD(cw_bat->alert_level)) {
|
|
+ dev_dbg(cw_bat->dev, "Setting new alert level\n");
|
|
+ reg_val &= ~CW2015_MASK_ATHD;
|
|
+ reg_val |= ~CW2015_ATHD(cw_bat->alert_level);
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_CONFIG, reg_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ ret = regmap_read(cw_bat->regmap, CW2015_REG_CONFIG, ®_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ if (!(reg_val & CW2015_CONFIG_UPDATE_FLG)) {
|
|
+ dev_dbg(cw_bat->dev,
|
|
+ "Battery profile not present, uploading battery profile\n");
|
|
+ if (cw_bat->bat_profile) {
|
|
+ ret = cw_update_profile(cw_bat);
|
|
+ if (ret) {
|
|
+ dev_err(cw_bat->dev,
|
|
+ "Failed to upload battery profile\n");
|
|
+ return ret;
|
|
+ }
|
|
+ } else {
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "No profile specified, continuing without profile\n");
|
|
+ }
|
|
+ } else if (cw_bat->bat_profile) {
|
|
+ u8 bat_info[CW2015_SIZE_BATINFO];
|
|
+
|
|
+ ret = regmap_raw_read(cw_bat->regmap, CW2015_REG_BATINFO,
|
|
+ bat_info, CW2015_SIZE_BATINFO);
|
|
+ if (ret) {
|
|
+ dev_err(cw_bat->dev,
|
|
+ "Failed to read stored battery profile\n");
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ if (memcmp(bat_info, cw_bat->bat_profile, CW2015_SIZE_BATINFO)) {
|
|
+ dev_warn(cw_bat->dev, "Replacing stored battery profile\n");
|
|
+ ret = cw_update_profile(cw_bat);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ }
|
|
+ } else {
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "Can't check current battery profile, no profile provided\n");
|
|
+ }
|
|
+
|
|
+ dev_dbg(cw_bat->dev, "Battery profile configured\n");
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int cw_power_on_reset(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret;
|
|
+ unsigned char reset_val;
|
|
+
|
|
+ reset_val = CW2015_MODE_SLEEP;
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_MODE, reset_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ /* wait for gauge to enter sleep */
|
|
+ msleep(20);
|
|
+
|
|
+ reset_val = CW2015_MODE_NORMAL;
|
|
+ ret = regmap_write(cw_bat->regmap, CW2015_REG_MODE, reset_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ ret = cw_init(cw_bat);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+#define HYSTERESIS(current, previous, up, down) \
|
|
+ (((current) < (previous) + (up)) && ((current) > (previous) - (down)))
|
|
+
|
|
+static int cw_get_soc(struct cw_battery *cw_bat)
|
|
+{
|
|
+ unsigned int soc;
|
|
+ int ret;
|
|
+
|
|
+ ret = regmap_read(cw_bat->regmap, CW2015_REG_SOC, &soc);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ if (soc > 100) {
|
|
+ int max_error_cycles =
|
|
+ CW2015_BAT_SOC_ERROR_MS / cw_bat->poll_interval_ms;
|
|
+
|
|
+ dev_err(cw_bat->dev, "Invalid SoC %d%%\n", soc);
|
|
+ cw_bat->read_errors++;
|
|
+ if (cw_bat->read_errors > max_error_cycles) {
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "Too many invalid SoC reports, resetting gauge\n");
|
|
+ cw_power_on_reset(cw_bat);
|
|
+ cw_bat->read_errors = 0;
|
|
+ }
|
|
+ return cw_bat->soc;
|
|
+ }
|
|
+ cw_bat->read_errors = 0;
|
|
+
|
|
+ /* Reset gauge if stuck while charging */
|
|
+ if (cw_bat->status == POWER_SUPPLY_STATUS_CHARGING && soc == cw_bat->soc) {
|
|
+ int max_stuck_cycles =
|
|
+ CW2015_BAT_CHARGING_STUCK_MS / cw_bat->poll_interval_ms;
|
|
+
|
|
+ cw_bat->charge_stuck_cnt++;
|
|
+ if (cw_bat->charge_stuck_cnt > max_stuck_cycles) {
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "SoC stuck @%u%%, resetting gauge\n", soc);
|
|
+ cw_power_on_reset(cw_bat);
|
|
+ cw_bat->charge_stuck_cnt = 0;
|
|
+ }
|
|
+ } else {
|
|
+ cw_bat->charge_stuck_cnt = 0;
|
|
+ }
|
|
+
|
|
+ /* Ignore voltage dips during charge */
|
|
+ if (cw_bat->charger_attached && HYSTERESIS(soc, cw_bat->soc, 0, 3))
|
|
+ soc = cw_bat->soc;
|
|
+
|
|
+ /* Ignore voltage spikes during discharge */
|
|
+ if (!cw_bat->charger_attached && HYSTERESIS(soc, cw_bat->soc, 3, 0))
|
|
+ soc = cw_bat->soc;
|
|
+
|
|
+ return soc;
|
|
+}
|
|
+
|
|
+static int cw_get_voltage(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret, i, voltage_mv;
|
|
+ u16 reg_val;
|
|
+ u32 avg = 0;
|
|
+
|
|
+ for (i = 0; i < CW2015_AVERAGING_SAMPLES; i++) {
|
|
+ ret = cw_read_word(cw_bat, CW2015_REG_VCELL, ®_val);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ avg += reg_val;
|
|
+ }
|
|
+ avg /= CW2015_AVERAGING_SAMPLES;
|
|
+
|
|
+ /*
|
|
+ * 305 uV per ADC step
|
|
+ * Use 312 / 1024 as efficient approximation of 305 / 1000
|
|
+ * Negligible error of 0.1%
|
|
+ */
|
|
+ voltage_mv = avg * 312 / 1024;
|
|
+
|
|
+ dev_dbg(cw_bat->dev, "Read voltage: %d mV, raw=0x%04x\n",
|
|
+ voltage_mv, reg_val);
|
|
+ return voltage_mv;
|
|
+}
|
|
+
|
|
+static int cw_get_time_to_empty(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret;
|
|
+ u16 value16;
|
|
+
|
|
+ ret = cw_read_word(cw_bat, CW2015_REG_RRT_ALERT, &value16);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+
|
|
+ return value16 & CW2015_MASK_SOC;
|
|
+}
|
|
+
|
|
+static void cw_update_charge_status(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int ret;
|
|
+
|
|
+ ret = power_supply_am_i_supplied(cw_bat->rk_bat);
|
|
+ if (ret < 0) {
|
|
+ dev_warn(cw_bat->dev, "Failed to get supply state: %d\n", ret);
|
|
+ } else {
|
|
+ bool charger_attached;
|
|
+
|
|
+ charger_attached = !!ret;
|
|
+ if (cw_bat->charger_attached != charger_attached) {
|
|
+ cw_bat->battery_changed = true;
|
|
+ if (charger_attached)
|
|
+ cw_bat->charge_count++;
|
|
+ }
|
|
+ cw_bat->charger_attached = charger_attached;
|
|
+ }
|
|
+}
|
|
+
|
|
+static void cw_update_soc(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int soc;
|
|
+
|
|
+ soc = cw_get_soc(cw_bat);
|
|
+ if (soc < 0)
|
|
+ dev_err(cw_bat->dev, "Failed to get SoC from gauge: %d\n", soc);
|
|
+ else if (cw_bat->soc != soc) {
|
|
+ cw_bat->soc = soc;
|
|
+ cw_bat->battery_changed = true;
|
|
+ }
|
|
+}
|
|
+
|
|
+static void cw_update_voltage(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int voltage_mv;
|
|
+
|
|
+ voltage_mv = cw_get_voltage(cw_bat);
|
|
+ if (voltage_mv < 0)
|
|
+ dev_err(cw_bat->dev, "Failed to get voltage from gauge: %d\n",
|
|
+ voltage_mv);
|
|
+ else
|
|
+ cw_bat->voltage_mv = voltage_mv;
|
|
+}
|
|
+
|
|
+static void cw_update_status(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int status = POWER_SUPPLY_STATUS_DISCHARGING;
|
|
+
|
|
+ if (cw_bat->charger_attached) {
|
|
+ if (cw_bat->soc >= 100)
|
|
+ status = POWER_SUPPLY_STATUS_FULL;
|
|
+ else
|
|
+ status = POWER_SUPPLY_STATUS_CHARGING;
|
|
+ }
|
|
+
|
|
+ if (cw_bat->status != status)
|
|
+ cw_bat->battery_changed = true;
|
|
+ cw_bat->status = status;
|
|
+}
|
|
+
|
|
+static void cw_update_time_to_empty(struct cw_battery *cw_bat)
|
|
+{
|
|
+ int time_to_empty;
|
|
+
|
|
+ time_to_empty = cw_get_time_to_empty(cw_bat);
|
|
+ if (time_to_empty < 0)
|
|
+ dev_err(cw_bat->dev, "Failed to get time to empty from gauge: %d\n",
|
|
+ time_to_empty);
|
|
+ else if (cw_bat->time_to_empty != time_to_empty) {
|
|
+ cw_bat->time_to_empty = time_to_empty;
|
|
+ cw_bat->battery_changed = true;
|
|
+ }
|
|
+}
|
|
+
|
|
+static void cw_bat_work(struct work_struct *work)
|
|
+{
|
|
+ struct delayed_work *delay_work;
|
|
+ struct cw_battery *cw_bat;
|
|
+ int ret;
|
|
+ unsigned int reg_val;
|
|
+
|
|
+ delay_work = to_delayed_work(work);
|
|
+ cw_bat = container_of(delay_work, struct cw_battery, battery_delay_work);
|
|
+ ret = regmap_read(cw_bat->regmap, CW2015_REG_MODE, ®_val);
|
|
+ if (ret) {
|
|
+ dev_err(cw_bat->dev, "Failed to read mode from gauge: %d\n", ret);
|
|
+ } else {
|
|
+ if ((reg_val & CW2015_MODE_SLEEP_MASK) == CW2015_MODE_SLEEP) {
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < CW2015_RESET_TRIES; i++) {
|
|
+ if (!cw_power_on_reset(cw_bat))
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ cw_update_soc(cw_bat);
|
|
+ cw_update_voltage(cw_bat);
|
|
+ cw_update_charge_status(cw_bat);
|
|
+ cw_update_status(cw_bat);
|
|
+ cw_update_time_to_empty(cw_bat);
|
|
+ }
|
|
+ dev_dbg(cw_bat->dev, "charger_attached = %d\n", cw_bat->charger_attached);
|
|
+ dev_dbg(cw_bat->dev, "status = %d\n", cw_bat->status);
|
|
+ dev_dbg(cw_bat->dev, "soc = %d%%\n", cw_bat->soc);
|
|
+ dev_dbg(cw_bat->dev, "voltage = %dmV\n", cw_bat->voltage_mv);
|
|
+
|
|
+ if (cw_bat->battery_changed)
|
|
+ power_supply_changed(cw_bat->rk_bat);
|
|
+ cw_bat->battery_changed = false;
|
|
+
|
|
+ queue_delayed_work(cw_bat->battery_workqueue,
|
|
+ &cw_bat->battery_delay_work,
|
|
+ msecs_to_jiffies(cw_bat->poll_interval_ms));
|
|
+}
|
|
+
|
|
+static bool cw_battery_valid_time_to_empty(struct cw_battery *cw_bat)
|
|
+{
|
|
+ return cw_bat->time_to_empty > 0 &&
|
|
+ cw_bat->time_to_empty < CW2015_MASK_SOC &&
|
|
+ cw_bat->status == POWER_SUPPLY_STATUS_DISCHARGING;
|
|
+}
|
|
+
|
|
+static int cw_battery_get_property(struct power_supply *psy,
|
|
+ enum power_supply_property psp,
|
|
+ union power_supply_propval *val)
|
|
+{
|
|
+ struct cw_battery *cw_bat;
|
|
+
|
|
+ cw_bat = power_supply_get_drvdata(psy);
|
|
+ switch (psp) {
|
|
+ case POWER_SUPPLY_PROP_CAPACITY:
|
|
+ val->intval = cw_bat->soc;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_STATUS:
|
|
+ val->intval = cw_bat->status;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_PRESENT:
|
|
+ val->intval = !!cw_bat->voltage_mv;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW:
|
|
+ val->intval = cw_bat->voltage_mv * 1000;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
|
|
+ if (cw_battery_valid_time_to_empty(cw_bat))
|
|
+ val->intval = cw_bat->time_to_empty;
|
|
+ else
|
|
+ val->intval = 0;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_TECHNOLOGY:
|
|
+ val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_CHARGE_COUNTER:
|
|
+ val->intval = cw_bat->charge_count;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_CHARGE_FULL:
|
|
+ case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
|
|
+ if (cw_bat->battery->charge_full_design_uah > 0)
|
|
+ val->intval = cw_bat->battery->charge_full_design_uah;
|
|
+ else
|
|
+ val->intval = 0;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_CHARGE_NOW:
|
|
+ val->intval = cw_bat->battery->charge_full_design_uah;
|
|
+ val->intval = val->intval * cw_bat->soc / 100;
|
|
+ break;
|
|
+
|
|
+ case POWER_SUPPLY_PROP_CURRENT_NOW:
|
|
+ if (cw_battery_valid_time_to_empty(cw_bat) &&
|
|
+ cw_bat->battery->charge_full_design_uah > 0) {
|
|
+ /* calculate remaining capacity */
|
|
+ val->intval = cw_bat->battery->charge_full_design_uah;
|
|
+ val->intval = val->intval * cw_bat->soc / 100;
|
|
+
|
|
+ /* estimate current based on time to empty */
|
|
+ val->intval = 60 * val->intval / cw_bat->time_to_empty;
|
|
+ } else {
|
|
+ val->intval = 0;
|
|
+ }
|
|
+
|
|
+ break;
|
|
+
|
|
+ default:
|
|
+ break;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static enum power_supply_property cw_battery_properties[] = {
|
|
+ POWER_SUPPLY_PROP_CAPACITY,
|
|
+ POWER_SUPPLY_PROP_STATUS,
|
|
+ POWER_SUPPLY_PROP_PRESENT,
|
|
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
|
|
+ POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
|
|
+ POWER_SUPPLY_PROP_TECHNOLOGY,
|
|
+ POWER_SUPPLY_PROP_CHARGE_COUNTER,
|
|
+ POWER_SUPPLY_PROP_CHARGE_FULL,
|
|
+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
|
|
+ POWER_SUPPLY_PROP_CHARGE_NOW,
|
|
+ POWER_SUPPLY_PROP_CURRENT_NOW,
|
|
+};
|
|
+
|
|
+static const struct power_supply_desc cw2015_bat_desc = {
|
|
+ .name = "cw2015-battery",
|
|
+ .type = POWER_SUPPLY_TYPE_BATTERY,
|
|
+ .properties = cw_battery_properties,
|
|
+ .num_properties = ARRAY_SIZE(cw_battery_properties),
|
|
+ .get_property = cw_battery_get_property,
|
|
+};
|
|
+
|
|
+static int cw2015_parse_properties(struct cw_battery *cw_bat)
|
|
+{
|
|
+ struct device *dev = cw_bat->dev;
|
|
+ int length;
|
|
+ int ret;
|
|
+
|
|
+ length = device_property_count_u8(dev, "cellwise,battery-profile");
|
|
+ if (length < 0) {
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "No battery-profile found, using current flash contents\n");
|
|
+ } else if (length != CW2015_SIZE_BATINFO) {
|
|
+ dev_err(cw_bat->dev, "battery-profile must be %d bytes\n",
|
|
+ CW2015_SIZE_BATINFO);
|
|
+ return -EINVAL;
|
|
+ } else {
|
|
+ cw_bat->bat_profile = devm_kzalloc(dev, length, GFP_KERNEL);
|
|
+ if (!cw_bat->bat_profile)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ ret = device_property_read_u8_array(dev,
|
|
+ "cellwise,battery-profile",
|
|
+ cw_bat->bat_profile,
|
|
+ length);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ ret = device_property_read_u32(dev, "cellwise,monitor-interval-ms",
|
|
+ &cw_bat->poll_interval_ms);
|
|
+ if (ret) {
|
|
+ dev_dbg(cw_bat->dev, "Using default poll interval\n");
|
|
+ cw_bat->poll_interval_ms = CW2015_DEFAULT_POLL_INTERVAL_MS;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct regmap_range regmap_ranges_rd_yes[] = {
|
|
+ regmap_reg_range(CW2015_REG_VERSION, CW2015_REG_VERSION),
|
|
+ regmap_reg_range(CW2015_REG_VCELL, CW2015_REG_CONFIG),
|
|
+ regmap_reg_range(CW2015_REG_MODE, CW2015_REG_MODE),
|
|
+ regmap_reg_range(CW2015_REG_BATINFO,
|
|
+ CW2015_REG_BATINFO + CW2015_SIZE_BATINFO - 1),
|
|
+};
|
|
+
|
|
+static const struct regmap_access_table regmap_rd_table = {
|
|
+ .yes_ranges = regmap_ranges_rd_yes,
|
|
+ .n_yes_ranges = 4,
|
|
+};
|
|
+
|
|
+static const struct regmap_range regmap_ranges_wr_yes[] = {
|
|
+ regmap_reg_range(CW2015_REG_RRT_ALERT, CW2015_REG_CONFIG),
|
|
+ regmap_reg_range(CW2015_REG_MODE, CW2015_REG_MODE),
|
|
+ regmap_reg_range(CW2015_REG_BATINFO,
|
|
+ CW2015_REG_BATINFO + CW2015_SIZE_BATINFO - 1),
|
|
+};
|
|
+
|
|
+static const struct regmap_access_table regmap_wr_table = {
|
|
+ .yes_ranges = regmap_ranges_wr_yes,
|
|
+ .n_yes_ranges = 3,
|
|
+};
|
|
+
|
|
+static const struct regmap_range regmap_ranges_vol_yes[] = {
|
|
+ regmap_reg_range(CW2015_REG_VCELL, CW2015_REG_SOC + 1),
|
|
+};
|
|
+
|
|
+static const struct regmap_access_table regmap_vol_table = {
|
|
+ .yes_ranges = regmap_ranges_vol_yes,
|
|
+ .n_yes_ranges = 1,
|
|
+};
|
|
+
|
|
+static const struct regmap_config cw2015_regmap_config = {
|
|
+ .reg_bits = 8,
|
|
+ .val_bits = 8,
|
|
+ .rd_table = ®map_rd_table,
|
|
+ .wr_table = ®map_wr_table,
|
|
+ .volatile_table = ®map_vol_table,
|
|
+ .max_register = CW2015_REG_BATINFO + CW2015_SIZE_BATINFO - 1,
|
|
+};
|
|
+
|
|
+static int cw_bat_probe(struct i2c_client *client)
|
|
+{
|
|
+ int ret;
|
|
+ struct cw_battery *cw_bat;
|
|
+ struct power_supply_config psy_cfg = { 0 };
|
|
+
|
|
+ cw_bat = devm_kzalloc(&client->dev, sizeof(*cw_bat), GFP_KERNEL);
|
|
+ if (!cw_bat)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ i2c_set_clientdata(client, cw_bat);
|
|
+ cw_bat->dev = &client->dev;
|
|
+ cw_bat->soc = 1;
|
|
+
|
|
+ ret = cw2015_parse_properties(cw_bat);
|
|
+ if (ret) {
|
|
+ dev_err(cw_bat->dev, "Failed to parse cw2015 properties\n");
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ cw_bat->regmap = devm_regmap_init_i2c(client, &cw2015_regmap_config);
|
|
+ if (IS_ERR(cw_bat->regmap)) {
|
|
+ dev_err(cw_bat->dev, "Failed to allocate regmap: %ld\n",
|
|
+ PTR_ERR(cw_bat->regmap));
|
|
+ return PTR_ERR(cw_bat->regmap);
|
|
+ }
|
|
+
|
|
+ ret = cw_init(cw_bat);
|
|
+ if (ret) {
|
|
+ dev_err(cw_bat->dev, "Init failed: %d\n", ret);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ psy_cfg.drv_data = cw_bat;
|
|
+ psy_cfg.fwnode = dev_fwnode(cw_bat->dev);
|
|
+
|
|
+ cw_bat->rk_bat = devm_power_supply_register(&client->dev,
|
|
+ &cw2015_bat_desc,
|
|
+ &psy_cfg);
|
|
+ if (IS_ERR(cw_bat->rk_bat)) {
|
|
+ /* try again if this happens */
|
|
+ dev_err_probe(&client->dev, PTR_ERR(cw_bat->rk_bat),
|
|
+ "Failed to register power supply\n");
|
|
+ return PTR_ERR(cw_bat->rk_bat);
|
|
+ }
|
|
+
|
|
+ ret = power_supply_get_battery_info(cw_bat->rk_bat, &cw_bat->battery);
|
|
+ if (ret) {
|
|
+ /* Allocate an empty battery */
|
|
+ cw_bat->battery = devm_kzalloc(&client->dev,
|
|
+ sizeof(*cw_bat->battery),
|
|
+ GFP_KERNEL);
|
|
+ if (!cw_bat->battery)
|
|
+ return -ENOMEM;
|
|
+ dev_warn(cw_bat->dev,
|
|
+ "No monitored battery, some properties will be missing\n");
|
|
+ }
|
|
+
|
|
+ cw_bat->battery_workqueue = create_singlethread_workqueue("rk_battery");
|
|
+ INIT_DELAYED_WORK(&cw_bat->battery_delay_work, cw_bat_work);
|
|
+ queue_delayed_work(cw_bat->battery_workqueue,
|
|
+ &cw_bat->battery_delay_work, msecs_to_jiffies(10));
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int __maybe_unused cw_bat_suspend(struct device *dev)
|
|
+{
|
|
+ struct i2c_client *client = to_i2c_client(dev);
|
|
+ struct cw_battery *cw_bat = i2c_get_clientdata(client);
|
|
+
|
|
+ cancel_delayed_work_sync(&cw_bat->battery_delay_work);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static int __maybe_unused cw_bat_resume(struct device *dev)
|
|
+{
|
|
+ struct i2c_client *client = to_i2c_client(dev);
|
|
+ struct cw_battery *cw_bat = i2c_get_clientdata(client);
|
|
+
|
|
+ queue_delayed_work(cw_bat->battery_workqueue,
|
|
+ &cw_bat->battery_delay_work, 0);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static SIMPLE_DEV_PM_OPS(cw_bat_pm_ops, cw_bat_suspend, cw_bat_resume);
|
|
+
|
|
+static int cw_bat_remove(struct i2c_client *client)
|
|
+{
|
|
+ struct cw_battery *cw_bat = i2c_get_clientdata(client);
|
|
+
|
|
+ cancel_delayed_work_sync(&cw_bat->battery_delay_work);
|
|
+ power_supply_put_battery_info(cw_bat->rk_bat, cw_bat->battery);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static const struct i2c_device_id cw_bat_id_table[] = {
|
|
+ { "cw2015", 0 },
|
|
+ { }
|
|
+};
|
|
+
|
|
+static const struct of_device_id cw2015_of_match[] = {
|
|
+ { .compatible = "cellwise,cw2015" },
|
|
+ { }
|
|
+};
|
|
+MODULE_DEVICE_TABLE(of, cw2015_of_match);
|
|
+
|
|
+static struct i2c_driver cw_bat_driver = {
|
|
+ .driver = {
|
|
+ .name = "cw2015",
|
|
+ .of_match_table = cw2015_of_match,
|
|
+ .pm = &cw_bat_pm_ops,
|
|
+ },
|
|
+ .probe_new = cw_bat_probe,
|
|
+ .remove = cw_bat_remove,
|
|
+ .id_table = cw_bat_id_table,
|
|
+};
|
|
+
|
|
+module_i2c_driver(cw_bat_driver);
|
|
+
|
|
+MODULE_AUTHOR("xhc<xhc@rock-chips.com>");
|
|
+MODULE_AUTHOR("Tobias Schramm <t.schramm@manjaro.org>");
|
|
+MODULE_DESCRIPTION("cw2015/cw2013 battery driver");
|
|
+MODULE_LICENSE("GPL");
|
|
diff -rupN linux.orig/include/linux/compiler.h linux/include/linux/compiler.h
|
|
--- linux.orig/include/linux/compiler.h 2022-11-01 17:55:30.018379377 -0400
|
|
+++ linux/include/linux/compiler.h 2022-11-01 17:56:17.144793376 -0400
|
|
@@ -213,6 +213,8 @@ void ftrace_likely_update(struct ftrace_
|
|
#define function_nocfi(x) (x)
|
|
#endif
|
|
|
|
+#include <asm/rwonce.h>
|
|
+
|
|
#endif /* __KERNEL__ */
|
|
|
|
/*
|
|
@@ -251,6 +253,4 @@ static inline void *offset_to_ptr(const
|
|
*/
|
|
#define prevent_tail_call_optimization() mb()
|
|
|
|
-#include <asm/rwonce.h>
|
|
-
|
|
#endif /* __LINUX_COMPILER_H */
|
|
diff -rupN linux.orig/include/linux/input-polldev.h linux/include/linux/input-polldev.h
|
|
--- linux.orig/include/linux/input-polldev.h 1969-12-31 19:00:00.000000000 -0500
|
|
+++ linux/include/linux/input-polldev.h 2022-11-01 17:56:17.144793376 -0400
|
|
@@ -0,0 +1,58 @@
|
|
+/* SPDX-License-Identifier: GPL-2.0-only */
|
|
+#ifndef _INPUT_POLLDEV_H
|
|
+#define _INPUT_POLLDEV_H
|
|
+
|
|
+/*
|
|
+ * Copyright (c) 2007 Dmitry Torokhov
|
|
+ */
|
|
+
|
|
+#include <linux/input.h>
|
|
+#include <linux/workqueue.h>
|
|
+
|
|
+/**
|
|
+ * struct input_polled_dev - simple polled input device
|
|
+ * @private: private driver data.
|
|
+ * @open: driver-supplied method that prepares device for polling
|
|
+ * (enabled the device and maybe flushes device state).
|
|
+ * @close: driver-supplied method that is called when device is no
|
|
+ * longer being polled. Used to put device into low power mode.
|
|
+ * @poll: driver-supplied method that polls the device and posts
|
|
+ * input events (mandatory).
|
|
+ * @poll_interval: specifies how often the poll() method should be called.
|
|
+ * Defaults to 500 msec unless overridden when registering the device.
|
|
+ * @poll_interval_max: specifies upper bound for the poll interval.
|
|
+ * Defaults to the initial value of @poll_interval.
|
|
+ * @poll_interval_min: specifies lower bound for the poll interval.
|
|
+ * Defaults to 0.
|
|
+ * @input: input device structure associated with the polled device.
|
|
+ * Must be properly initialized by the driver (id, name, phys, bits).
|
|
+ *
|
|
+ * Polled input device provides a skeleton for supporting simple input
|
|
+ * devices that do not raise interrupts but have to be periodically
|
|
+ * scanned or polled to detect changes in their state.
|
|
+ */
|
|
+struct input_polled_dev {
|
|
+ void *private;
|
|
+
|
|
+ void (*open)(struct input_polled_dev *dev);
|
|
+ void (*close)(struct input_polled_dev *dev);
|
|
+ void (*poll)(struct input_polled_dev *dev);
|
|
+ unsigned int poll_interval; /* msec */
|
|
+ unsigned int poll_interval_max; /* msec */
|
|
+ unsigned int poll_interval_min; /* msec */
|
|
+
|
|
+ struct input_dev *input;
|
|
+
|
|
+/* private: */
|
|
+ struct delayed_work work;
|
|
+
|
|
+ bool devres_managed;
|
|
+};
|
|
+
|
|
+struct input_polled_dev *input_allocate_polled_device(void);
|
|
+struct input_polled_dev *devm_input_allocate_polled_device(struct device *dev);
|
|
+void input_free_polled_device(struct input_polled_dev *dev);
|
|
+int input_register_polled_device(struct input_polled_dev *dev);
|
|
+void input_unregister_polled_device(struct input_polled_dev *dev);
|
|
+
|
|
+#endif
|
|
diff -rupN linux.orig/Makefile linux/Makefile
|
|
--- linux.orig/Makefile 2022-11-01 17:55:23.054625866 -0400
|
|
+++ linux/Makefile 2022-11-01 17:56:17.128793891 -0400
|
|
@@ -755,6 +755,8 @@ KBUILD_CFLAGS += $(call cc-disable-warni
|
|
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
|
|
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
|
|
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
|
|
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-label)
|
|
+KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
|
|
|
|
ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
|
|
KBUILD_CFLAGS += -O2
|
|
@@ -1002,7 +1004,7 @@ endif
|
|
KBUILD_CFLAGS += -Werror=date-time
|
|
|
|
# enforce correct pointer usage
|
|
-KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
|
|
+# KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
|
|
|
|
# Require designated initializers for all marked structures
|
|
KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
|