Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branches 'ib-mfd-leds-4.16', 'ib-mfd-memstick-misc-mmc-4.16', 'ib-mfd-platform-4.16' and 'ib-mfd-tty-watchdog-4.16', tag 'ib-extcon-mfd-4.16-1' into ibs-for-mfd-merged

Immutable branch for both MFD and EXTCON tree.

+2659 -146
+39
Documentation/devicetree/bindings/watchdog/zii,rave-sp-wdt.txt
··· 1 + Zodiac Inflight Innovations RAVE Supervisory Processor Watchdog Bindings 2 + 3 + RAVE SP watchdog device is a "MFD cell" device corresponding to 4 + watchdog functionality of RAVE Supervisory Processor. It is expected 5 + that its Device Tree node is specified as a child of the node 6 + corresponding to the parent RAVE SP device (as documented in 7 + Documentation/devicetree/bindings/mfd/zii,rave-sp.txt) 8 + 9 + Required properties: 10 + 11 + - compatible: Depending on wire protocol implemented by RAVE SP 12 + firmware, should be one of: 13 + - "zii,rave-sp-watchdog" 14 + - "zii,rave-sp-watchdog-legacy" 15 + 16 + Optional properties: 17 + 18 + - wdt-timeout: Two byte nvmem cell specified as per 19 + Documentation/devicetree/bindings/nvmem/nvmem.txt 20 + 21 + Example: 22 + 23 + rave-sp { 24 + compatible = "zii,rave-sp-rdu1"; 25 + current-speed = <38400>; 26 + 27 + eeprom { 28 + wdt_timeout: wdt-timeout@8E { 29 + reg = <0x8E 2>; 30 + }; 31 + }; 32 + 33 + watchdog { 34 + compatible = "zii,rave-sp-watchdog"; 35 + nvmem-cells = <&wdt_timeout>; 36 + nvmem-cell-names = "wdt-timeout"; 37 + }; 38 + } 39 +
+3
Documentation/driver-model/devres.txt
··· 384 384 devm_reset_control_get() 385 385 devm_reset_controller_register() 386 386 387 + SERDEV 388 + devm_serdev_device_open() 389 + 387 390 SLAVE DMA ENGINE 388 391 devm_acpi_dma_controller_register() 389 392
+4 -35
drivers/extcon/extcon-axp288.c
··· 24 24 #include <linux/notifier.h> 25 25 #include <linux/extcon-provider.h> 26 26 #include <linux/regmap.h> 27 - #include <linux/gpio.h> 28 - #include <linux/gpio/consumer.h> 29 27 #include <linux/mfd/axp20x.h> 30 28 31 29 /* Power source status register */ ··· 77 79 AXP288_BC_DET_STAT_REG = 0x2f, 78 80 }; 79 81 80 - enum axp288_mux_select { 81 - EXTCON_GPIO_MUX_SEL_PMIC = 0, 82 - EXTCON_GPIO_MUX_SEL_SOC, 83 - }; 84 - 85 82 enum axp288_extcon_irq { 86 83 VBUS_FALLING_IRQ = 0, 87 84 VBUS_RISING_IRQ, ··· 97 104 struct device *dev; 98 105 struct regmap *regmap; 99 106 struct regmap_irq_chip_data *regmap_irqc; 100 - struct gpio_desc *gpio_mux_cntl; 101 107 int irq[EXTCON_IRQ_END]; 102 108 struct extcon_dev *edev; 103 - struct notifier_block extcon_nb; 104 109 unsigned int previous_cable; 105 110 }; 106 111 ··· 188 197 } 189 198 190 199 no_vbus: 191 - /* 192 - * If VBUS is absent Connect D+/D- lines to PMIC for BC 193 - * detection. Else connect them to SOC for USB communication. 194 - */ 195 - if (info->gpio_mux_cntl) 196 - gpiod_set_value(info->gpio_mux_cntl, 197 - vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC 198 - : EXTCON_GPIO_MUX_SEL_PMIC); 199 - 200 200 extcon_set_state_sync(info->edev, info->previous_cable, false); 201 201 if (info->previous_cable == EXTCON_CHG_USB_SDP) 202 202 extcon_set_state_sync(info->edev, EXTCON_USB, false); ··· 235 253 { 236 254 struct axp288_extcon_info *info; 237 255 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); 238 - struct axp288_extcon_pdata *pdata = pdev->dev.platform_data; 239 - int ret, i, pirq, gpio; 256 + int ret, i, pirq; 240 257 241 258 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 242 259 if (!info) ··· 245 264 info->regmap = axp20x->regmap; 246 265 info->regmap_irqc = axp20x->regmap_irqc; 247 266 info->previous_cable = EXTCON_NONE; 248 - if (pdata) 249 - info->gpio_mux_cntl = pdata->gpio_mux_cntl; 250 267 251 268 platform_set_drvdata(pdev, info); 252 269 ··· 265 286 return ret; 266 287 } 267 288 268 - /* Set up gpio control for USB Mux */ 269 - if (info->gpio_mux_cntl) { 270 - gpio = desc_to_gpio(info->gpio_mux_cntl); 271 - ret = devm_gpio_request(&pdev->dev, gpio, "USB_MUX"); 272 - if (ret < 0) { 273 - dev_err(&pdev->dev, 274 - "failed to request the gpio=%d\n", gpio); 275 - return ret; 276 - } 277 - gpiod_direction_output(info->gpio_mux_cntl, 278 - EXTCON_GPIO_MUX_SEL_PMIC); 279 - } 280 - 281 289 for (i = 0; i < EXTCON_IRQ_END; i++) { 282 290 pirq = platform_get_irq(pdev, i); 291 + if (pirq < 0) 292 + return pirq; 293 + 283 294 info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq); 284 295 if (info->irq[i] < 0) { 285 296 dev_err(&pdev->dev,
+137 -3
drivers/extcon/extcon-usbc-cros-ec.c
··· 34 34 35 35 struct notifier_block notifier; 36 36 37 + unsigned int dr; /* data role */ 38 + bool pr; /* power role (true if VBUS enabled) */ 37 39 bool dp; /* DisplayPort enabled */ 38 40 bool mux; /* SuperSpeed (usb3) enabled */ 39 41 unsigned int power_type; 40 42 }; 41 43 42 44 static const unsigned int usb_type_c_cable[] = { 45 + EXTCON_USB, 46 + EXTCON_USB_HOST, 43 47 EXTCON_DISP_DP, 44 48 EXTCON_NONE, 49 + }; 50 + 51 + enum usb_data_roles { 52 + DR_NONE, 53 + DR_HOST, 54 + DR_DEVICE, 45 55 }; 46 56 47 57 /** ··· 160 150 pd_control.port = info->port_id; 161 151 pd_control.role = USB_PD_CTRL_ROLE_NO_CHANGE; 162 152 pd_control.mux = USB_PD_CTRL_MUX_NO_CHANGE; 153 + pd_control.swap = USB_PD_CTRL_SWAP_NONE; 163 154 ret = cros_ec_pd_command(info, EC_CMD_USB_PD_CONTROL, 1, 164 155 &pd_control, sizeof(pd_control), 165 156 &resp, sizeof(resp)); ··· 194 183 return resp.num_ports; 195 184 } 196 185 186 + static const char *cros_ec_usb_role_string(unsigned int role) 187 + { 188 + return role == DR_NONE ? "DISCONNECTED" : 189 + (role == DR_HOST ? "DFP" : "UFP"); 190 + } 191 + 192 + static const char *cros_ec_usb_power_type_string(unsigned int type) 193 + { 194 + switch (type) { 195 + case USB_CHG_TYPE_NONE: 196 + return "USB_CHG_TYPE_NONE"; 197 + case USB_CHG_TYPE_PD: 198 + return "USB_CHG_TYPE_PD"; 199 + case USB_CHG_TYPE_PROPRIETARY: 200 + return "USB_CHG_TYPE_PROPRIETARY"; 201 + case USB_CHG_TYPE_C: 202 + return "USB_CHG_TYPE_C"; 203 + case USB_CHG_TYPE_BC12_DCP: 204 + return "USB_CHG_TYPE_BC12_DCP"; 205 + case USB_CHG_TYPE_BC12_CDP: 206 + return "USB_CHG_TYPE_BC12_CDP"; 207 + case USB_CHG_TYPE_BC12_SDP: 208 + return "USB_CHG_TYPE_BC12_SDP"; 209 + case USB_CHG_TYPE_OTHER: 210 + return "USB_CHG_TYPE_OTHER"; 211 + case USB_CHG_TYPE_VBUS: 212 + return "USB_CHG_TYPE_VBUS"; 213 + case USB_CHG_TYPE_UNKNOWN: 214 + return "USB_CHG_TYPE_UNKNOWN"; 215 + default: 216 + return "USB_CHG_TYPE_UNKNOWN"; 217 + } 218 + } 219 + 220 + static bool cros_ec_usb_power_type_is_wall_wart(unsigned int type, 221 + unsigned int role) 222 + { 223 + switch (type) { 224 + /* FIXME : Guppy, Donnettes, and other chargers will be miscategorized 225 + * because they identify with USB_CHG_TYPE_C, but we can't return true 226 + * here from that code because that breaks Suzy-Q and other kinds of 227 + * USB Type-C cables and peripherals. 228 + */ 229 + case USB_CHG_TYPE_PROPRIETARY: 230 + case USB_CHG_TYPE_BC12_DCP: 231 + return true; 232 + case USB_CHG_TYPE_PD: 233 + case USB_CHG_TYPE_C: 234 + case USB_CHG_TYPE_BC12_CDP: 235 + case USB_CHG_TYPE_BC12_SDP: 236 + case USB_CHG_TYPE_OTHER: 237 + case USB_CHG_TYPE_VBUS: 238 + case USB_CHG_TYPE_UNKNOWN: 239 + case USB_CHG_TYPE_NONE: 240 + default: 241 + return false; 242 + } 243 + } 244 + 197 245 static int extcon_cros_ec_detect_cable(struct cros_ec_extcon_info *info, 198 246 bool force) 199 247 { 200 248 struct device *dev = info->dev; 201 249 int role, power_type; 250 + unsigned int dr = DR_NONE; 251 + bool pr = false; 202 252 bool polarity = false; 203 253 bool dp = false; 204 254 bool mux = false; ··· 278 206 dev_err(dev, "failed getting role err = %d\n", role); 279 207 return role; 280 208 } 209 + dev_dbg(dev, "disconnected\n"); 281 210 } else { 282 211 int pd_mux_state; 283 212 213 + dr = (role & PD_CTRL_RESP_ROLE_DATA) ? DR_HOST : DR_DEVICE; 214 + pr = (role & PD_CTRL_RESP_ROLE_POWER); 284 215 pd_mux_state = cros_ec_usb_get_pd_mux_state(info); 285 216 if (pd_mux_state < 0) 286 217 pd_mux_state = USB_PD_MUX_USB_ENABLED; ··· 291 216 dp = pd_mux_state & USB_PD_MUX_DP_ENABLED; 292 217 mux = pd_mux_state & USB_PD_MUX_USB_ENABLED; 293 218 hpd = pd_mux_state & USB_PD_MUX_HPD_IRQ; 219 + 220 + dev_dbg(dev, 221 + "connected role 0x%x pwr type %d dr %d pr %d pol %d mux %d dp %d hpd %d\n", 222 + role, power_type, dr, pr, polarity, mux, dp, hpd); 294 223 } 295 224 296 - if (force || info->dp != dp || info->mux != mux || 297 - info->power_type != power_type) { 225 + /* 226 + * When there is no USB host (e.g. USB PD charger), 227 + * we are not really a UFP for the AP. 228 + */ 229 + if (dr == DR_DEVICE && 230 + cros_ec_usb_power_type_is_wall_wart(power_type, role)) 231 + dr = DR_NONE; 298 232 233 + if (force || info->dr != dr || info->pr != pr || info->dp != dp || 234 + info->mux != mux || info->power_type != power_type) { 235 + bool host_connected = false, device_connected = false; 236 + 237 + dev_dbg(dev, "Type/Role switch! type = %s role = %s\n", 238 + cros_ec_usb_power_type_string(power_type), 239 + cros_ec_usb_role_string(dr)); 240 + info->dr = dr; 241 + info->pr = pr; 299 242 info->dp = dp; 300 243 info->mux = mux; 301 244 info->power_type = power_type; 302 245 303 - extcon_set_state(info->edev, EXTCON_DISP_DP, dp); 246 + if (dr == DR_DEVICE) 247 + device_connected = true; 248 + else if (dr == DR_HOST) 249 + host_connected = true; 304 250 251 + extcon_set_state(info->edev, EXTCON_USB, device_connected); 252 + extcon_set_state(info->edev, EXTCON_USB_HOST, host_connected); 253 + extcon_set_state(info->edev, EXTCON_DISP_DP, dp); 254 + extcon_set_property(info->edev, EXTCON_USB, 255 + EXTCON_PROP_USB_VBUS, 256 + (union extcon_property_value)(int)pr); 257 + extcon_set_property(info->edev, EXTCON_USB_HOST, 258 + EXTCON_PROP_USB_VBUS, 259 + (union extcon_property_value)(int)pr); 260 + extcon_set_property(info->edev, EXTCON_USB, 261 + EXTCON_PROP_USB_TYPEC_POLARITY, 262 + (union extcon_property_value)(int)polarity); 263 + extcon_set_property(info->edev, EXTCON_USB_HOST, 264 + EXTCON_PROP_USB_TYPEC_POLARITY, 265 + (union extcon_property_value)(int)polarity); 305 266 extcon_set_property(info->edev, EXTCON_DISP_DP, 306 267 EXTCON_PROP_USB_TYPEC_POLARITY, 307 268 (union extcon_property_value)(int)polarity); 269 + extcon_set_property(info->edev, EXTCON_USB, 270 + EXTCON_PROP_USB_SS, 271 + (union extcon_property_value)(int)mux); 272 + extcon_set_property(info->edev, EXTCON_USB_HOST, 273 + EXTCON_PROP_USB_SS, 274 + (union extcon_property_value)(int)mux); 308 275 extcon_set_property(info->edev, EXTCON_DISP_DP, 309 276 EXTCON_PROP_USB_SS, 310 277 (union extcon_property_value)(int)mux); ··· 354 237 EXTCON_PROP_DISP_HPD, 355 238 (union extcon_property_value)(int)hpd); 356 239 240 + extcon_sync(info->edev, EXTCON_USB); 241 + extcon_sync(info->edev, EXTCON_USB_HOST); 357 242 extcon_sync(info->edev, EXTCON_DISP_DP); 358 243 359 244 } else if (hpd) { ··· 441 322 return ret; 442 323 } 443 324 325 + extcon_set_property_capability(info->edev, EXTCON_USB, 326 + EXTCON_PROP_USB_VBUS); 327 + extcon_set_property_capability(info->edev, EXTCON_USB_HOST, 328 + EXTCON_PROP_USB_VBUS); 329 + extcon_set_property_capability(info->edev, EXTCON_USB, 330 + EXTCON_PROP_USB_TYPEC_POLARITY); 331 + extcon_set_property_capability(info->edev, EXTCON_USB_HOST, 332 + EXTCON_PROP_USB_TYPEC_POLARITY); 444 333 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 445 334 EXTCON_PROP_USB_TYPEC_POLARITY); 335 + extcon_set_property_capability(info->edev, EXTCON_USB, 336 + EXTCON_PROP_USB_SS); 337 + extcon_set_property_capability(info->edev, EXTCON_USB_HOST, 338 + EXTCON_PROP_USB_SS); 446 339 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 447 340 EXTCON_PROP_USB_SS); 448 341 extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 449 342 EXTCON_PROP_DISP_HPD); 343 + 344 + info->dr = DR_NONE; 345 + info->pr = false; 450 346 451 347 platform_set_drvdata(pdev, info); 452 348
+1 -1
drivers/leds/leds-pm8058.c
··· 106 106 if (!led) 107 107 return -ENOMEM; 108 108 109 - led->ledtype = (u32)of_device_get_match_data(&pdev->dev); 109 + led->ledtype = (u32)(unsigned long)of_device_get_match_data(&pdev->dev); 110 110 111 111 map = dev_get_regmap(pdev->dev.parent, NULL); 112 112 if (!map) {
+2 -2
drivers/memstick/host/Kconfig
··· 45 45 46 46 config MEMSTICK_REALTEK_PCI 47 47 tristate "Realtek PCI-E Memstick Card Interface Driver" 48 - depends on MFD_RTSX_PCI 48 + depends on MISC_RTSX_PCI 49 49 help 50 50 Say Y here to include driver code to support Memstick card interface 51 51 of Realtek PCI-E card reader ··· 55 55 56 56 config MEMSTICK_REALTEK_USB 57 57 tristate "Realtek USB Memstick Card Interface Driver" 58 - depends on MFD_RTSX_USB 58 + depends on MISC_RTSX_USB 59 59 help 60 60 Say Y here to include driver code to support Memstick card interface 61 61 of Realtek RTS5129/39 series USB card reader
+1 -1
drivers/memstick/host/rtsx_pci_ms.c
··· 24 24 #include <linux/delay.h> 25 25 #include <linux/platform_device.h> 26 26 #include <linux/memstick.h> 27 - #include <linux/mfd/rtsx_pci.h> 27 + #include <linux/rtsx_pci.h> 28 28 #include <asm/unaligned.h> 29 29 30 30 struct realtek_pci_ms {
+1 -1
drivers/memstick/host/rtsx_usb_ms.c
··· 25 25 #include <linux/workqueue.h> 26 26 #include <linux/memstick.h> 27 27 #include <linux/kthread.h> 28 - #include <linux/mfd/rtsx_usb.h> 28 + #include <linux/rtsx_usb.h> 29 29 #include <linux/pm_runtime.h> 30 30 #include <linux/mutex.h> 31 31 #include <linux/sched.h>
+18 -21
drivers/mfd/Kconfig
··· 222 222 response time cannot be guaranteed, we support ignoring 223 223 'pre-amble' bytes before the response actually starts. 224 224 225 + config MFD_CROS_EC_CHARDEV 226 + tristate "Chrome OS Embedded Controller userspace device interface" 227 + depends on MFD_CROS_EC 228 + select CROS_EC_CTL 229 + ---help--- 230 + This driver adds support to talk with the ChromeOS EC from userspace. 231 + 232 + If you have a supported Chromebook, choose Y or M here. 233 + The module will be called cros_ec_dev. 234 + 225 235 config MFD_ASIC3 226 236 bool "Compaq ASIC3" 227 237 depends on GPIOLIB && ARM ··· 939 929 southbridge which provides access to GPIOs and Watchdog using the 940 930 southbridge PCI device configuration space. 941 931 942 - config MFD_RTSX_PCI 943 - tristate "Realtek PCI-E card reader" 944 - depends on PCI 945 - select MFD_CORE 946 - help 947 - This supports for Realtek PCI-Express card reader including rts5209, 948 - rts5227, rts522A, rts5229, rts5249, rts524A, rts525A, rtl8411, etc. 949 - Realtek card reader supports access to many types of memory cards, 950 - such as Memory Stick, Memory Stick Pro, Secure Digital and 951 - MultiMediaCard. 952 - 953 932 config MFD_RT5033 954 933 tristate "Richtek RT5033 Power Management IC" 955 934 depends on I2C ··· 951 952 common support for accessing the device. The device supports multiple 952 953 sub-devices like charger, fuel gauge, flash LED, current source, 953 954 LDO and Buck. 954 - 955 - config MFD_RTSX_USB 956 - tristate "Realtek USB card reader" 957 - depends on USB 958 - select MFD_CORE 959 - help 960 - Select this option to get support for Realtek USB 2.0 card readers 961 - including RTS5129, RTS5139, RTS5179 and RTS5170. 962 - Realtek card reader supports access to many types of memory cards, 963 - such as Memory Stick Pro, Secure Digital and MultiMediaCard. 964 955 965 956 config MFD_RC5T583 966 957 bool "Ricoh RC5T583 Power Management system device" ··· 1847 1858 help 1848 1859 System Registers are the platform configuration block 1849 1860 on the ARM Ltd. Versatile Express board. 1861 + 1862 + config RAVE_SP_CORE 1863 + tristate "RAVE SP MCU core driver" 1864 + depends on SERIAL_DEV_BUS 1865 + select CRC_CCITT 1866 + help 1867 + Select this to get support for the Supervisory Processor 1868 + device found on several devices in RAVE line of hardware. 1850 1869 1851 1870 endmenu 1852 1871 endif
+3 -4
drivers/mfd/Makefile
··· 17 17 obj-$(CONFIG_MFD_CROS_EC) += cros_ec_core.o 18 18 obj-$(CONFIG_MFD_CROS_EC_I2C) += cros_ec_i2c.o 19 19 obj-$(CONFIG_MFD_CROS_EC_SPI) += cros_ec_spi.o 20 + obj-$(CONFIG_MFD_CROS_EC_CHARDEV) += cros_ec_dev.o 20 21 obj-$(CONFIG_MFD_EXYNOS_LPASS) += exynos-lpass.o 21 - 22 - rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o 23 - obj-$(CONFIG_MFD_RTSX_PCI) += rtsx_pci.o 24 - obj-$(CONFIG_MFD_RTSX_USB) += rtsx_usb.o 25 22 26 23 obj-$(CONFIG_HTC_PASIC3) += htc-pasic3.o 27 24 obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o ··· 227 230 obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o 228 231 obj-$(CONFIG_MFD_MXS_LRADC) += mxs-lradc.o 229 232 obj-$(CONFIG_MFD_SC27XX_PMIC) += sprd-sc27xx-spi.o 233 + obj-$(CONFIG_RAVE_SP_CORE) += rave-sp.o 234 +
+2 -2
drivers/mfd/cros_ec.c
··· 40 40 }; 41 41 42 42 static const struct mfd_cell ec_cell = { 43 - .name = "cros-ec-ctl", 43 + .name = "cros-ec-dev", 44 44 .platform_data = &ec_p, 45 45 .pdata_size = sizeof(ec_p), 46 46 }; 47 47 48 48 static const struct mfd_cell ec_pd_cell = { 49 - .name = "cros-ec-ctl", 49 + .name = "cros-ec-dev", 50 50 .platform_data = &pd_p, 51 51 .pdata_size = sizeof(pd_p), 52 52 };
+710
drivers/mfd/rave-sp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + 3 + /* 4 + * Multifunction core driver for Zodiac Inflight Innovations RAVE 5 + * Supervisory Processor(SP) MCU that is connected via dedicated UART 6 + * port 7 + * 8 + * Copyright (C) 2017 Zodiac Inflight Innovations 9 + */ 10 + 11 + #include <linux/atomic.h> 12 + #include <linux/crc-ccitt.h> 13 + #include <linux/delay.h> 14 + #include <linux/export.h> 15 + #include <linux/init.h> 16 + #include <linux/slab.h> 17 + #include <linux/kernel.h> 18 + #include <linux/mfd/rave-sp.h> 19 + #include <linux/module.h> 20 + #include <linux/of.h> 21 + #include <linux/of_device.h> 22 + #include <linux/sched.h> 23 + #include <linux/serdev.h> 24 + #include <asm/unaligned.h> 25 + 26 + /* 27 + * UART protocol using following entities: 28 + * - message to MCU => ACK response 29 + * - event from MCU => event ACK 30 + * 31 + * Frame structure: 32 + * <STX> <DATA> <CHECKSUM> <ETX> 33 + * Where: 34 + * - STX - is start of transmission character 35 + * - ETX - end of transmission 36 + * - DATA - payload 37 + * - CHECKSUM - checksum calculated on <DATA> 38 + * 39 + * If <DATA> or <CHECKSUM> contain one of control characters, then it is 40 + * escaped using <DLE> control code. Added <DLE> does not participate in 41 + * checksum calculation. 42 + */ 43 + #define RAVE_SP_STX 0x02 44 + #define RAVE_SP_ETX 0x03 45 + #define RAVE_SP_DLE 0x10 46 + 47 + #define RAVE_SP_MAX_DATA_SIZE 64 48 + #define RAVE_SP_CHECKSUM_SIZE 2 /* Worst case scenario on RDU2 */ 49 + /* 50 + * We don't store STX, ETX and unescaped bytes, so Rx is only 51 + * DATA + CSUM 52 + */ 53 + #define RAVE_SP_RX_BUFFER_SIZE \ 54 + (RAVE_SP_MAX_DATA_SIZE + RAVE_SP_CHECKSUM_SIZE) 55 + 56 + #define RAVE_SP_STX_ETX_SIZE 2 57 + /* 58 + * For Tx we have to have space for everything, STX, EXT and 59 + * potentially stuffed DATA + CSUM data + csum 60 + */ 61 + #define RAVE_SP_TX_BUFFER_SIZE \ 62 + (RAVE_SP_STX_ETX_SIZE + 2 * RAVE_SP_RX_BUFFER_SIZE) 63 + 64 + #define RAVE_SP_BOOT_SOURCE_GET 0 65 + #define RAVE_SP_BOOT_SOURCE_SET 1 66 + 67 + #define RAVE_SP_RDU2_BOARD_TYPE_RMB 0 68 + #define RAVE_SP_RDU2_BOARD_TYPE_DEB 1 69 + 70 + #define RAVE_SP_BOOT_SOURCE_SD 0 71 + #define RAVE_SP_BOOT_SOURCE_EMMC 1 72 + #define RAVE_SP_BOOT_SOURCE_NOR 2 73 + 74 + /** 75 + * enum rave_sp_deframer_state - Possible state for de-framer 76 + * 77 + * @RAVE_SP_EXPECT_SOF: Scanning input for start-of-frame marker 78 + * @RAVE_SP_EXPECT_DATA: Got start of frame marker, collecting frame 79 + * @RAVE_SP_EXPECT_ESCAPED_DATA: Got escape character, collecting escaped byte 80 + */ 81 + enum rave_sp_deframer_state { 82 + RAVE_SP_EXPECT_SOF, 83 + RAVE_SP_EXPECT_DATA, 84 + RAVE_SP_EXPECT_ESCAPED_DATA, 85 + }; 86 + 87 + /** 88 + * struct rave_sp_deframer - Device protocol deframer 89 + * 90 + * @state: Current state of the deframer 91 + * @data: Buffer used to collect deframed data 92 + * @length: Number of bytes de-framed so far 93 + */ 94 + struct rave_sp_deframer { 95 + enum rave_sp_deframer_state state; 96 + unsigned char data[RAVE_SP_RX_BUFFER_SIZE]; 97 + size_t length; 98 + }; 99 + 100 + /** 101 + * struct rave_sp_reply - Reply as per RAVE device protocol 102 + * 103 + * @length: Expected reply length 104 + * @data: Buffer to store reply payload in 105 + * @code: Expected reply code 106 + * @ackid: Expected reply ACK ID 107 + * @completion: Successful reply reception completion 108 + */ 109 + struct rave_sp_reply { 110 + size_t length; 111 + void *data; 112 + u8 code; 113 + u8 ackid; 114 + struct completion received; 115 + }; 116 + 117 + /** 118 + * struct rave_sp_checksum - Variant specific checksum implementation details 119 + * 120 + * @length: Caculated checksum length 121 + * @subroutine: Utilized checksum algorithm implementation 122 + */ 123 + struct rave_sp_checksum { 124 + size_t length; 125 + void (*subroutine)(const u8 *, size_t, u8 *); 126 + }; 127 + 128 + /** 129 + * struct rave_sp_variant_cmds - Variant specific command routines 130 + * 131 + * @translate: Generic to variant specific command mapping routine 132 + * 133 + */ 134 + struct rave_sp_variant_cmds { 135 + int (*translate)(enum rave_sp_command); 136 + }; 137 + 138 + /** 139 + * struct rave_sp_variant - RAVE supervisory processor core variant 140 + * 141 + * @checksum: Variant specific checksum implementation 142 + * @cmd: Variant specific command pointer table 143 + * 144 + */ 145 + struct rave_sp_variant { 146 + const struct rave_sp_checksum *checksum; 147 + struct rave_sp_variant_cmds cmd; 148 + }; 149 + 150 + /** 151 + * struct rave_sp - RAVE supervisory processor core 152 + * 153 + * @serdev: Pointer to underlying serdev 154 + * @deframer: Stored state of the protocol deframer 155 + * @ackid: ACK ID used in last reply sent to the device 156 + * @bus_lock: Lock to serialize access to the device 157 + * @reply_lock: Lock protecting @reply 158 + * @reply: Pointer to memory to store reply payload 159 + * 160 + * @variant: Device variant specific information 161 + * @event_notifier_list: Input event notification chain 162 + * 163 + */ 164 + struct rave_sp { 165 + struct serdev_device *serdev; 166 + struct rave_sp_deframer deframer; 167 + atomic_t ackid; 168 + struct mutex bus_lock; 169 + struct mutex reply_lock; 170 + struct rave_sp_reply *reply; 171 + 172 + const struct rave_sp_variant *variant; 173 + struct blocking_notifier_head event_notifier_list; 174 + }; 175 + 176 + static bool rave_sp_id_is_event(u8 code) 177 + { 178 + return (code & 0xF0) == RAVE_SP_EVNT_BASE; 179 + } 180 + 181 + static void rave_sp_unregister_event_notifier(struct device *dev, void *res) 182 + { 183 + struct rave_sp *sp = dev_get_drvdata(dev->parent); 184 + struct notifier_block *nb = *(struct notifier_block **)res; 185 + struct blocking_notifier_head *bnh = &sp->event_notifier_list; 186 + 187 + WARN_ON(blocking_notifier_chain_unregister(bnh, nb)); 188 + } 189 + 190 + int devm_rave_sp_register_event_notifier(struct device *dev, 191 + struct notifier_block *nb) 192 + { 193 + struct rave_sp *sp = dev_get_drvdata(dev->parent); 194 + struct notifier_block **rcnb; 195 + int ret; 196 + 197 + rcnb = devres_alloc(rave_sp_unregister_event_notifier, 198 + sizeof(*rcnb), GFP_KERNEL); 199 + if (!rcnb) 200 + return -ENOMEM; 201 + 202 + ret = blocking_notifier_chain_register(&sp->event_notifier_list, nb); 203 + if (!ret) { 204 + *rcnb = nb; 205 + devres_add(dev, rcnb); 206 + } else { 207 + devres_free(rcnb); 208 + } 209 + 210 + return ret; 211 + } 212 + EXPORT_SYMBOL_GPL(devm_rave_sp_register_event_notifier); 213 + 214 + static void csum_8b2c(const u8 *buf, size_t size, u8 *crc) 215 + { 216 + *crc = *buf++; 217 + size--; 218 + 219 + while (size--) 220 + *crc += *buf++; 221 + 222 + *crc = 1 + ~(*crc); 223 + } 224 + 225 + static void csum_ccitt(const u8 *buf, size_t size, u8 *crc) 226 + { 227 + const u16 calculated = crc_ccitt_false(0xffff, buf, size); 228 + 229 + /* 230 + * While the rest of the wire protocol is little-endian, 231 + * CCITT-16 CRC in RDU2 device is sent out in big-endian order. 232 + */ 233 + put_unaligned_be16(calculated, crc); 234 + } 235 + 236 + static void *stuff(unsigned char *dest, const unsigned char *src, size_t n) 237 + { 238 + while (n--) { 239 + const unsigned char byte = *src++; 240 + 241 + switch (byte) { 242 + case RAVE_SP_STX: 243 + case RAVE_SP_ETX: 244 + case RAVE_SP_DLE: 245 + *dest++ = RAVE_SP_DLE; 246 + /* FALLTHROUGH */ 247 + default: 248 + *dest++ = byte; 249 + } 250 + } 251 + 252 + return dest; 253 + } 254 + 255 + static int rave_sp_write(struct rave_sp *sp, const u8 *data, u8 data_size) 256 + { 257 + const size_t checksum_length = sp->variant->checksum->length; 258 + unsigned char frame[RAVE_SP_TX_BUFFER_SIZE]; 259 + unsigned char crc[RAVE_SP_CHECKSUM_SIZE]; 260 + unsigned char *dest = frame; 261 + size_t length; 262 + 263 + if (WARN_ON(checksum_length > sizeof(crc))) 264 + return -ENOMEM; 265 + 266 + if (WARN_ON(data_size > sizeof(frame))) 267 + return -ENOMEM; 268 + 269 + sp->variant->checksum->subroutine(data, data_size, crc); 270 + 271 + *dest++ = RAVE_SP_STX; 272 + dest = stuff(dest, data, data_size); 273 + dest = stuff(dest, crc, checksum_length); 274 + *dest++ = RAVE_SP_ETX; 275 + 276 + length = dest - frame; 277 + 278 + print_hex_dump(KERN_DEBUG, "rave-sp tx: ", DUMP_PREFIX_NONE, 279 + 16, 1, frame, length, false); 280 + 281 + return serdev_device_write(sp->serdev, frame, length, HZ); 282 + } 283 + 284 + static u8 rave_sp_reply_code(u8 command) 285 + { 286 + /* 287 + * There isn't a single rule that describes command code -> 288 + * ACK code transformation, but, going through various 289 + * versions of ICDs, there appear to be three distinct groups 290 + * that can be described by simple transformation. 291 + */ 292 + switch (command) { 293 + case 0xA0 ... 0xBE: 294 + /* 295 + * Commands implemented by firmware found in RDU1 and 296 + * older devices all seem to obey the following rule 297 + */ 298 + return command + 0x20; 299 + case 0xE0 ... 0xEF: 300 + /* 301 + * Events emitted by all versions of the firmare use 302 + * least significant bit to get an ACK code 303 + */ 304 + return command | 0x01; 305 + default: 306 + /* 307 + * Commands implemented by firmware found in RDU2 are 308 + * similar to "old" commands, but they use slightly 309 + * different offset 310 + */ 311 + return command + 0x40; 312 + } 313 + } 314 + 315 + int rave_sp_exec(struct rave_sp *sp, 316 + void *__data, size_t data_size, 317 + void *reply_data, size_t reply_data_size) 318 + { 319 + struct rave_sp_reply reply = { 320 + .data = reply_data, 321 + .length = reply_data_size, 322 + .received = COMPLETION_INITIALIZER_ONSTACK(reply.received), 323 + }; 324 + unsigned char *data = __data; 325 + int command, ret = 0; 326 + u8 ackid; 327 + 328 + command = sp->variant->cmd.translate(data[0]); 329 + if (command < 0) 330 + return command; 331 + 332 + ackid = atomic_inc_return(&sp->ackid); 333 + reply.ackid = ackid; 334 + reply.code = rave_sp_reply_code((u8)command), 335 + 336 + mutex_lock(&sp->bus_lock); 337 + 338 + mutex_lock(&sp->reply_lock); 339 + sp->reply = &reply; 340 + mutex_unlock(&sp->reply_lock); 341 + 342 + data[0] = command; 343 + data[1] = ackid; 344 + 345 + rave_sp_write(sp, data, data_size); 346 + 347 + if (!wait_for_completion_timeout(&reply.received, HZ)) { 348 + dev_err(&sp->serdev->dev, "Command timeout\n"); 349 + ret = -ETIMEDOUT; 350 + 351 + mutex_lock(&sp->reply_lock); 352 + sp->reply = NULL; 353 + mutex_unlock(&sp->reply_lock); 354 + } 355 + 356 + mutex_unlock(&sp->bus_lock); 357 + return ret; 358 + } 359 + EXPORT_SYMBOL_GPL(rave_sp_exec); 360 + 361 + static void rave_sp_receive_event(struct rave_sp *sp, 362 + const unsigned char *data, size_t length) 363 + { 364 + u8 cmd[] = { 365 + [0] = rave_sp_reply_code(data[0]), 366 + [1] = data[1], 367 + }; 368 + 369 + rave_sp_write(sp, cmd, sizeof(cmd)); 370 + 371 + blocking_notifier_call_chain(&sp->event_notifier_list, 372 + rave_sp_action_pack(data[0], data[2]), 373 + NULL); 374 + } 375 + 376 + static void rave_sp_receive_reply(struct rave_sp *sp, 377 + const unsigned char *data, size_t length) 378 + { 379 + struct device *dev = &sp->serdev->dev; 380 + struct rave_sp_reply *reply; 381 + const size_t payload_length = length - 2; 382 + 383 + mutex_lock(&sp->reply_lock); 384 + reply = sp->reply; 385 + 386 + if (reply) { 387 + if (reply->code == data[0] && reply->ackid == data[1] && 388 + payload_length >= reply->length) { 389 + /* 390 + * We are relying on memcpy(dst, src, 0) to be a no-op 391 + * when handling commands that have a no-payload reply 392 + */ 393 + memcpy(reply->data, &data[2], reply->length); 394 + complete(&reply->received); 395 + sp->reply = NULL; 396 + } else { 397 + dev_err(dev, "Ignoring incorrect reply\n"); 398 + dev_dbg(dev, "Code: expected = 0x%08x received = 0x%08x\n", 399 + reply->code, data[0]); 400 + dev_dbg(dev, "ACK ID: expected = 0x%08x received = 0x%08x\n", 401 + reply->ackid, data[1]); 402 + dev_dbg(dev, "Length: expected = %zu received = %zu\n", 403 + reply->length, payload_length); 404 + } 405 + } 406 + 407 + mutex_unlock(&sp->reply_lock); 408 + } 409 + 410 + static void rave_sp_receive_frame(struct rave_sp *sp, 411 + const unsigned char *data, 412 + size_t length) 413 + { 414 + const size_t checksum_length = sp->variant->checksum->length; 415 + const size_t payload_length = length - checksum_length; 416 + const u8 *crc_reported = &data[payload_length]; 417 + struct device *dev = &sp->serdev->dev; 418 + u8 crc_calculated[checksum_length]; 419 + 420 + print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE, 421 + 16, 1, data, length, false); 422 + 423 + if (unlikely(length <= checksum_length)) { 424 + dev_warn(dev, "Dropping short frame\n"); 425 + return; 426 + } 427 + 428 + sp->variant->checksum->subroutine(data, payload_length, 429 + crc_calculated); 430 + 431 + if (memcmp(crc_calculated, crc_reported, checksum_length)) { 432 + dev_warn(dev, "Dropping bad frame\n"); 433 + return; 434 + } 435 + 436 + if (rave_sp_id_is_event(data[0])) 437 + rave_sp_receive_event(sp, data, length); 438 + else 439 + rave_sp_receive_reply(sp, data, length); 440 + } 441 + 442 + static int rave_sp_receive_buf(struct serdev_device *serdev, 443 + const unsigned char *buf, size_t size) 444 + { 445 + struct device *dev = &serdev->dev; 446 + struct rave_sp *sp = dev_get_drvdata(dev); 447 + struct rave_sp_deframer *deframer = &sp->deframer; 448 + const unsigned char *src = buf; 449 + const unsigned char *end = buf + size; 450 + 451 + while (src < end) { 452 + const unsigned char byte = *src++; 453 + 454 + switch (deframer->state) { 455 + case RAVE_SP_EXPECT_SOF: 456 + if (byte == RAVE_SP_STX) 457 + deframer->state = RAVE_SP_EXPECT_DATA; 458 + break; 459 + 460 + case RAVE_SP_EXPECT_DATA: 461 + /* 462 + * Treat special byte values first 463 + */ 464 + switch (byte) { 465 + case RAVE_SP_ETX: 466 + rave_sp_receive_frame(sp, 467 + deframer->data, 468 + deframer->length); 469 + /* 470 + * Once we extracted a complete frame 471 + * out of a stream, we call it done 472 + * and proceed to bailing out while 473 + * resetting the framer to initial 474 + * state, regardless if we've consumed 475 + * all of the stream or not. 476 + */ 477 + goto reset_framer; 478 + case RAVE_SP_STX: 479 + dev_warn(dev, "Bad frame: STX before ETX\n"); 480 + /* 481 + * If we encounter second "start of 482 + * the frame" marker before seeing 483 + * corresponding "end of frame", we 484 + * reset the framer and ignore both: 485 + * frame started by first SOF and 486 + * frame started by current SOF. 487 + * 488 + * NOTE: The above means that only the 489 + * frame started by third SOF, sent 490 + * after this one will have a chance 491 + * to get throught. 492 + */ 493 + goto reset_framer; 494 + case RAVE_SP_DLE: 495 + deframer->state = RAVE_SP_EXPECT_ESCAPED_DATA; 496 + /* 497 + * If we encounter escape sequence we 498 + * need to skip it and collect the 499 + * byte that follows. We do it by 500 + * forcing the next iteration of the 501 + * encompassing while loop. 502 + */ 503 + continue; 504 + } 505 + /* 506 + * For the rest of the bytes, that are not 507 + * speical snoflakes, we do the same thing 508 + * that we do to escaped data - collect it in 509 + * deframer buffer 510 + */ 511 + 512 + /* FALLTHROUGH */ 513 + 514 + case RAVE_SP_EXPECT_ESCAPED_DATA: 515 + deframer->data[deframer->length++] = byte; 516 + 517 + if (deframer->length == sizeof(deframer->data)) { 518 + dev_warn(dev, "Bad frame: Too long\n"); 519 + /* 520 + * If the amount of data we've 521 + * accumulated for current frame so 522 + * far starts to exceed the capacity 523 + * of deframer's buffer, there's 524 + * nothing else we can do but to 525 + * discard that data and start 526 + * assemblying a new frame again 527 + */ 528 + goto reset_framer; 529 + } 530 + 531 + /* 532 + * We've extracted out special byte, now we 533 + * can go back to regular data collecting 534 + */ 535 + deframer->state = RAVE_SP_EXPECT_DATA; 536 + break; 537 + } 538 + } 539 + 540 + /* 541 + * The only way to get out of the above loop and end up here 542 + * is throught consuming all of the supplied data, so here we 543 + * report that we processed it all. 544 + */ 545 + return size; 546 + 547 + reset_framer: 548 + /* 549 + * NOTE: A number of codepaths that will drop us here will do 550 + * so before consuming all 'size' bytes of the data passed by 551 + * serdev layer. We rely on the fact that serdev layer will 552 + * re-execute this handler with the remainder of the Rx bytes 553 + * once we report actual number of bytes that we processed. 554 + */ 555 + deframer->state = RAVE_SP_EXPECT_SOF; 556 + deframer->length = 0; 557 + 558 + return src - buf; 559 + } 560 + 561 + static int rave_sp_rdu1_cmd_translate(enum rave_sp_command command) 562 + { 563 + if (command >= RAVE_SP_CMD_STATUS && 564 + command <= RAVE_SP_CMD_CONTROL_EVENTS) 565 + return command; 566 + 567 + return -EINVAL; 568 + } 569 + 570 + static int rave_sp_rdu2_cmd_translate(enum rave_sp_command command) 571 + { 572 + if (command >= RAVE_SP_CMD_GET_FIRMWARE_VERSION && 573 + command <= RAVE_SP_CMD_GET_GPIO_STATE) 574 + return command; 575 + 576 + if (command == RAVE_SP_CMD_REQ_COPPER_REV) { 577 + /* 578 + * As per RDU2 ICD 3.4.47 CMD_GET_COPPER_REV code is 579 + * different from that for RDU1 and it is set to 0x28. 580 + */ 581 + return 0x28; 582 + } 583 + 584 + return rave_sp_rdu1_cmd_translate(command); 585 + } 586 + 587 + static int rave_sp_default_cmd_translate(enum rave_sp_command command) 588 + { 589 + /* 590 + * All of the following command codes were taken from "Table : 591 + * Communications Protocol Message Types" in section 3.3 592 + * "MESSAGE TYPES" of Rave PIC24 ICD. 593 + */ 594 + switch (command) { 595 + case RAVE_SP_CMD_GET_FIRMWARE_VERSION: 596 + return 0x11; 597 + case RAVE_SP_CMD_GET_BOOTLOADER_VERSION: 598 + return 0x12; 599 + case RAVE_SP_CMD_BOOT_SOURCE: 600 + return 0x14; 601 + case RAVE_SP_CMD_SW_WDT: 602 + return 0x1C; 603 + case RAVE_SP_CMD_RESET: 604 + return 0x1E; 605 + case RAVE_SP_CMD_RESET_REASON: 606 + return 0x1F; 607 + default: 608 + return -EINVAL; 609 + } 610 + } 611 + 612 + static const struct rave_sp_checksum rave_sp_checksum_8b2c = { 613 + .length = 1, 614 + .subroutine = csum_8b2c, 615 + }; 616 + 617 + static const struct rave_sp_checksum rave_sp_checksum_ccitt = { 618 + .length = 2, 619 + .subroutine = csum_ccitt, 620 + }; 621 + 622 + static const struct rave_sp_variant rave_sp_legacy = { 623 + .checksum = &rave_sp_checksum_8b2c, 624 + .cmd = { 625 + .translate = rave_sp_default_cmd_translate, 626 + }, 627 + }; 628 + 629 + static const struct rave_sp_variant rave_sp_rdu1 = { 630 + .checksum = &rave_sp_checksum_8b2c, 631 + .cmd = { 632 + .translate = rave_sp_rdu1_cmd_translate, 633 + }, 634 + }; 635 + 636 + static const struct rave_sp_variant rave_sp_rdu2 = { 637 + .checksum = &rave_sp_checksum_ccitt, 638 + .cmd = { 639 + .translate = rave_sp_rdu2_cmd_translate, 640 + }, 641 + }; 642 + 643 + static const struct of_device_id rave_sp_dt_ids[] = { 644 + { .compatible = "zii,rave-sp-niu", .data = &rave_sp_legacy }, 645 + { .compatible = "zii,rave-sp-mezz", .data = &rave_sp_legacy }, 646 + { .compatible = "zii,rave-sp-esb", .data = &rave_sp_legacy }, 647 + { .compatible = "zii,rave-sp-rdu1", .data = &rave_sp_rdu1 }, 648 + { .compatible = "zii,rave-sp-rdu2", .data = &rave_sp_rdu2 }, 649 + { /* sentinel */ } 650 + }; 651 + 652 + static const struct serdev_device_ops rave_sp_serdev_device_ops = { 653 + .receive_buf = rave_sp_receive_buf, 654 + .write_wakeup = serdev_device_write_wakeup, 655 + }; 656 + 657 + static int rave_sp_probe(struct serdev_device *serdev) 658 + { 659 + struct device *dev = &serdev->dev; 660 + struct rave_sp *sp; 661 + u32 baud; 662 + int ret; 663 + 664 + if (of_property_read_u32(dev->of_node, "current-speed", &baud)) { 665 + dev_err(dev, 666 + "'current-speed' is not specified in device node\n"); 667 + return -EINVAL; 668 + } 669 + 670 + sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL); 671 + if (!sp) 672 + return -ENOMEM; 673 + 674 + sp->serdev = serdev; 675 + dev_set_drvdata(dev, sp); 676 + 677 + sp->variant = of_device_get_match_data(dev); 678 + if (!sp->variant) 679 + return -ENODEV; 680 + 681 + mutex_init(&sp->bus_lock); 682 + mutex_init(&sp->reply_lock); 683 + BLOCKING_INIT_NOTIFIER_HEAD(&sp->event_notifier_list); 684 + 685 + serdev_device_set_client_ops(serdev, &rave_sp_serdev_device_ops); 686 + ret = devm_serdev_device_open(dev, serdev); 687 + if (ret) 688 + return ret; 689 + 690 + serdev_device_set_baudrate(serdev, baud); 691 + 692 + return devm_of_platform_populate(dev); 693 + } 694 + 695 + MODULE_DEVICE_TABLE(of, rave_sp_dt_ids); 696 + 697 + static struct serdev_device_driver rave_sp_drv = { 698 + .probe = rave_sp_probe, 699 + .driver = { 700 + .name = "rave-sp", 701 + .of_match_table = rave_sp_dt_ids, 702 + }, 703 + }; 704 + module_serdev_device_driver(rave_sp_drv); 705 + 706 + MODULE_LICENSE("GPL"); 707 + MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>"); 708 + MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>"); 709 + MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>"); 710 + MODULE_DESCRIPTION("RAVE SP core driver");
+1 -1
drivers/mfd/rtl8411.c drivers/misc/cardreader/rtl8411.c
··· 23 23 #include <linux/module.h> 24 24 #include <linux/bitops.h> 25 25 #include <linux/delay.h> 26 - #include <linux/mfd/rtsx_pci.h> 26 + #include <linux/rtsx_pci.h> 27 27 28 28 #include "rtsx_pcr.h" 29 29
+1 -1
drivers/mfd/rts5209.c drivers/misc/cardreader/rts5209.c
··· 21 21 22 22 #include <linux/module.h> 23 23 #include <linux/delay.h> 24 - #include <linux/mfd/rtsx_pci.h> 24 + #include <linux/rtsx_pci.h> 25 25 26 26 #include "rtsx_pcr.h" 27 27
+1 -1
drivers/mfd/rts5227.c drivers/misc/cardreader/rts5227.c
··· 22 22 23 23 #include <linux/module.h> 24 24 #include <linux/delay.h> 25 - #include <linux/mfd/rtsx_pci.h> 25 + #include <linux/rtsx_pci.h> 26 26 27 27 #include "rtsx_pcr.h" 28 28
+1 -1
drivers/mfd/rts5229.c drivers/misc/cardreader/rts5229.c
··· 21 21 22 22 #include <linux/module.h> 23 23 #include <linux/delay.h> 24 - #include <linux/mfd/rtsx_pci.h> 24 + #include <linux/rtsx_pci.h> 25 25 26 26 #include "rtsx_pcr.h" 27 27
+1 -2
drivers/mfd/rts5249.c drivers/misc/cardreader/rts5249.c
··· 21 21 22 22 #include <linux/module.h> 23 23 #include <linux/delay.h> 24 - #include <linux/mfd/rtsx_pci.h> 24 + #include <linux/rtsx_pci.h> 25 25 26 26 #include "rtsx_pcr.h" 27 27 ··· 738 738 pcr->reg_pm_ctrl3 = RTS524A_PM_CTRL3; 739 739 pcr->ops = &rts525a_pcr_ops; 740 740 } 741 -
+123 -2
drivers/mfd/rtsx_pcr.c drivers/misc/cardreader/rtsx_pcr.c
··· 29 29 #include <linux/idr.h> 30 30 #include <linux/platform_device.h> 31 31 #include <linux/mfd/core.h> 32 - #include <linux/mfd/rtsx_pci.h> 32 + #include <linux/rtsx_pci.h> 33 33 #include <linux/mmc/card.h> 34 34 #include <asm/unaligned.h> 35 35 ··· 62 62 { PCI_DEVICE(0x10EC, 0x5286), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 63 63 { PCI_DEVICE(0x10EC, 0x524A), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 64 64 { PCI_DEVICE(0x10EC, 0x525A), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 65 + { PCI_DEVICE(0x10EC, 0x5260), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 65 66 { 0, } 66 67 }; 67 68 ··· 335 334 336 335 void rtsx_pci_stop_cmd(struct rtsx_pcr *pcr) 337 336 { 337 + if (pcr->ops->stop_cmd) 338 + return pcr->ops->stop_cmd(pcr); 339 + 338 340 rtsx_pci_writel(pcr, RTSX_HCBCTLR, STOP_CMD); 339 341 rtsx_pci_writel(pcr, RTSX_HDBCTLR, STOP_DMA); 340 342 ··· 830 826 return err; 831 827 832 828 /* Wait SSC clock stable */ 833 - udelay(10); 829 + udelay(SSC_CLOCK_STABLE_WAIT); 834 830 err = rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, 0); 835 831 if (err < 0) 836 832 return err; ··· 967 963 pcr->slots[RTSX_MS_CARD].p_dev); 968 964 } 969 965 966 + void rtsx_pci_process_ocp(struct rtsx_pcr *pcr) 967 + { 968 + if (pcr->ops->process_ocp) 969 + pcr->ops->process_ocp(pcr); 970 + } 971 + 972 + int rtsx_pci_process_ocp_interrupt(struct rtsx_pcr *pcr) 973 + { 974 + if (pcr->option.ocp_en) 975 + rtsx_pci_process_ocp(pcr); 976 + 977 + return 0; 978 + } 979 + 970 980 static irqreturn_t rtsx_pci_isr(int irq, void *dev_id) 971 981 { 972 982 struct rtsx_pcr *pcr = dev_id; ··· 1004 986 } 1005 987 1006 988 int_reg &= (pcr->bier | 0x7FFFFF); 989 + 990 + if (int_reg & SD_OC_INT) 991 + rtsx_pci_process_ocp_interrupt(pcr); 1007 992 1008 993 if (int_reg & SD_INT) { 1009 994 if (int_reg & SD_EXIST) { ··· 1140 1119 } 1141 1120 #endif 1142 1121 1122 + void rtsx_pci_enable_ocp(struct rtsx_pcr *pcr) 1123 + { 1124 + u8 val = SD_OCP_INT_EN | SD_DETECT_EN; 1125 + 1126 + if (pcr->ops->enable_ocp) 1127 + pcr->ops->enable_ocp(pcr); 1128 + else 1129 + rtsx_pci_write_register(pcr, REG_OCPCTL, 0xFF, val); 1130 + 1131 + } 1132 + 1133 + void rtsx_pci_disable_ocp(struct rtsx_pcr *pcr) 1134 + { 1135 + u8 mask = SD_OCP_INT_EN | SD_DETECT_EN; 1136 + 1137 + if (pcr->ops->disable_ocp) 1138 + pcr->ops->disable_ocp(pcr); 1139 + else 1140 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 1141 + } 1142 + 1143 + void rtsx_pci_init_ocp(struct rtsx_pcr *pcr) 1144 + { 1145 + if (pcr->ops->init_ocp) { 1146 + pcr->ops->init_ocp(pcr); 1147 + } else { 1148 + struct rtsx_cr_option *option = &(pcr->option); 1149 + 1150 + if (option->ocp_en) { 1151 + u8 val = option->sd_400mA_ocp_thd; 1152 + 1153 + rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, 0); 1154 + rtsx_pci_write_register(pcr, REG_OCPPARA1, 1155 + SD_OCP_TIME_MASK, SD_OCP_TIME_800); 1156 + rtsx_pci_write_register(pcr, REG_OCPPARA2, 1157 + SD_OCP_THD_MASK, val); 1158 + rtsx_pci_write_register(pcr, REG_OCPGLITCH, 1159 + SD_OCP_GLITCH_MASK, pcr->hw_param.ocp_glitch); 1160 + rtsx_pci_enable_ocp(pcr); 1161 + } else { 1162 + /* OC power down */ 1163 + rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, 1164 + OC_POWER_DOWN); 1165 + } 1166 + } 1167 + } 1168 + 1169 + int rtsx_pci_get_ocpstat(struct rtsx_pcr *pcr, u8 *val) 1170 + { 1171 + if (pcr->ops->get_ocpstat) 1172 + return pcr->ops->get_ocpstat(pcr, val); 1173 + else 1174 + return rtsx_pci_read_register(pcr, REG_OCPSTAT, val); 1175 + } 1176 + 1177 + void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr) 1178 + { 1179 + if (pcr->ops->clear_ocpstat) { 1180 + pcr->ops->clear_ocpstat(pcr); 1181 + } else { 1182 + u8 mask = SD_OCP_INT_CLR | SD_OC_CLR; 1183 + u8 val = SD_OCP_INT_CLR | SD_OC_CLR; 1184 + 1185 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, val); 1186 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 1187 + } 1188 + } 1189 + 1190 + int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr) 1191 + { 1192 + rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN | 1193 + MS_CLK_EN | SD40_CLK_EN, 0); 1194 + rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, 0); 1195 + 1196 + rtsx_pci_card_power_off(pcr, RTSX_SD_CARD); 1197 + 1198 + msleep(50); 1199 + 1200 + rtsx_pci_card_pull_ctl_disable(pcr, RTSX_SD_CARD); 1201 + 1202 + return 0; 1203 + } 1204 + 1205 + int rtsx_ms_power_off_card3v3(struct rtsx_pcr *pcr) 1206 + { 1207 + rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN | 1208 + MS_CLK_EN | SD40_CLK_EN, 0); 1209 + 1210 + rtsx_pci_card_pull_ctl_disable(pcr, RTSX_MS_CARD); 1211 + 1212 + rtsx_pci_write_register(pcr, CARD_OE, MS_OUTPUT_EN, 0); 1213 + rtsx_pci_card_power_off(pcr, RTSX_MS_CARD); 1214 + 1215 + return 0; 1216 + } 1217 + 1143 1218 static int rtsx_pci_init_hw(struct rtsx_pcr *pcr) 1144 1219 { 1145 1220 int err; ··· 1306 1189 case PID_5250: 1307 1190 case PID_524A: 1308 1191 case PID_525A: 1192 + case PID_5260: 1309 1193 rtsx_pci_write_register(pcr, PM_CLK_FORCE_CTL, 1, 1); 1310 1194 break; 1311 1195 default: ··· 1382 1264 1383 1265 case 0x5286: 1384 1266 rtl8402_init_params(pcr); 1267 + break; 1268 + case 0x5260: 1269 + rts5260_init_params(pcr); 1385 1270 break; 1386 1271 } 1387 1272
+11 -1
drivers/mfd/rtsx_pcr.h drivers/misc/cardreader/rtsx_pcr.h
··· 22 22 #ifndef __RTSX_PCR_H 23 23 #define __RTSX_PCR_H 24 24 25 - #include <linux/mfd/rtsx_pci.h> 25 + #include <linux/rtsx_pci.h> 26 26 27 27 #define MIN_DIV_N_PCR 80 28 28 #define MAX_DIV_N_PCR 208 ··· 44 44 #define ASPM_MASK_NEG 0xFC 45 45 #define MASK_8_BIT_DEF 0xFF 46 46 47 + #define SSC_CLOCK_STABLE_WAIT 130 48 + 47 49 int __rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val); 48 50 int __rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val); 49 51 ··· 59 57 void rts524a_init_params(struct rtsx_pcr *pcr); 60 58 void rts525a_init_params(struct rtsx_pcr *pcr); 61 59 void rtl8411b_init_params(struct rtsx_pcr *pcr); 60 + void rts5260_init_params(struct rtsx_pcr *pcr); 62 61 63 62 static inline u8 map_sd_drive(int idx) 64 63 { ··· 102 99 int rtsx_gops_pm_reset(struct rtsx_pcr *pcr); 103 100 int rtsx_set_ltr_latency(struct rtsx_pcr *pcr, u32 latency); 104 101 int rtsx_set_l1off_sub(struct rtsx_pcr *pcr, u8 val); 102 + void rtsx_pci_init_ocp(struct rtsx_pcr *pcr); 103 + void rtsx_pci_disable_ocp(struct rtsx_pcr *pcr); 104 + void rtsx_pci_enable_ocp(struct rtsx_pcr *pcr); 105 + int rtsx_pci_get_ocpstat(struct rtsx_pcr *pcr, u8 *val); 106 + void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr); 107 + int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr); 108 + int rtsx_ms_power_off_card3v3(struct rtsx_pcr *pcr); 105 109 106 110 #endif
+1 -1
drivers/mfd/rtsx_usb.c drivers/misc/cardreader/rtsx_usb.c
··· 23 23 #include <linux/usb.h> 24 24 #include <linux/platform_device.h> 25 25 #include <linux/mfd/core.h> 26 - #include <linux/mfd/rtsx_usb.h> 26 + #include <linux/rtsx_usb.h> 27 27 28 28 static int polling_pipe = 1; 29 29 module_param(polling_pipe, int, S_IRUGO | S_IWUSR);
+5
drivers/misc/Kconfig
··· 496 496 Enable this configuration option to enable the host side test driver 497 497 for PCI Endpoint. 498 498 499 + config MISC_RTSX 500 + tristate 501 + default MISC_RTSX_PCI || MISC_RTSX_USB 502 + 499 503 source "drivers/misc/c2port/Kconfig" 500 504 source "drivers/misc/eeprom/Kconfig" 501 505 source "drivers/misc/cb710/Kconfig" ··· 512 508 source "drivers/misc/genwqe/Kconfig" 513 509 source "drivers/misc/echo/Kconfig" 514 510 source "drivers/misc/cxl/Kconfig" 511 + source "drivers/misc/cardreader/Kconfig" 515 512 endmenu
+1
drivers/misc/Makefile
··· 55 55 obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o 56 56 obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o 57 57 obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o 58 + obj-$(CONFIG_MISC_RTSX) += cardreader/ 58 59 59 60 lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o 60 61 lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
+20
drivers/misc/cardreader/Kconfig
··· 1 + config MISC_RTSX_PCI 2 + tristate "Realtek PCI-E card reader" 3 + depends on PCI 4 + select MFD_CORE 5 + help 6 + This supports for Realtek PCI-Express card reader including rts5209, 7 + rts5227, rts522A, rts5229, rts5249, rts524A, rts525A, rtl8411, rts5260. 8 + Realtek card readers support access to many types of memory cards, 9 + such as Memory Stick, Memory Stick Pro, Secure Digital and 10 + MultiMediaCard. 11 + 12 + config MISC_RTSX_USB 13 + tristate "Realtek USB card reader" 14 + depends on USB 15 + select MFD_CORE 16 + help 17 + Select this option to get support for Realtek USB 2.0 card readers 18 + including RTS5129, RTS5139, RTS5179 and RTS5170. 19 + Realtek card reader supports access to many types of memory cards, 20 + such as Memory Stick Pro, Secure Digital and MultiMediaCard.
+4
drivers/misc/cardreader/Makefile
··· 1 + rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o 2 + 3 + obj-$(CONFIG_MISC_RTSX_PCI) += rtsx_pci.o 4 + obj-$(CONFIG_MISC_RTSX_USB) += rtsx_usb.o
+748
drivers/misc/cardreader/rts5260.c
··· 1 + /* Driver for Realtek PCI-Express card reader 2 + * 3 + * Copyright(c) 2016-2017 Realtek Semiconductor Corp. All rights reserved. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms of the GNU General Public License as published by the 7 + * Free Software Foundation; either version 2, or (at your option) any 8 + * later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, but 11 + * WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 + * General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License along 16 + * with this program; if not, see <http://www.gnu.org/licenses/>. 17 + * 18 + * Author: 19 + * Steven FENG <steven_feng@realsil.com.cn> 20 + * Rui FENG <rui_feng@realsil.com.cn> 21 + * Wei WANG <wei_wang@realsil.com.cn> 22 + */ 23 + 24 + #include <linux/module.h> 25 + #include <linux/delay.h> 26 + #include <linux/rtsx_pci.h> 27 + 28 + #include "rts5260.h" 29 + #include "rtsx_pcr.h" 30 + 31 + static u8 rts5260_get_ic_version(struct rtsx_pcr *pcr) 32 + { 33 + u8 val; 34 + 35 + rtsx_pci_read_register(pcr, DUMMY_REG_RESET_0, &val); 36 + return val & IC_VERSION_MASK; 37 + } 38 + 39 + static void rts5260_fill_driving(struct rtsx_pcr *pcr, u8 voltage) 40 + { 41 + u8 driving_3v3[6][3] = { 42 + {0x94, 0x94, 0x94}, 43 + {0x11, 0x11, 0x18}, 44 + {0x55, 0x55, 0x5C}, 45 + {0x94, 0x94, 0x94}, 46 + {0x94, 0x94, 0x94}, 47 + {0xFF, 0xFF, 0xFF}, 48 + }; 49 + u8 driving_1v8[6][3] = { 50 + {0x9A, 0x89, 0x89}, 51 + {0xC4, 0xC4, 0xC4}, 52 + {0x3C, 0x3C, 0x3C}, 53 + {0x9B, 0x99, 0x99}, 54 + {0x9A, 0x89, 0x89}, 55 + {0xFE, 0xFE, 0xFE}, 56 + }; 57 + u8 (*driving)[3], drive_sel; 58 + 59 + if (voltage == OUTPUT_3V3) { 60 + driving = driving_3v3; 61 + drive_sel = pcr->sd30_drive_sel_3v3; 62 + } else { 63 + driving = driving_1v8; 64 + drive_sel = pcr->sd30_drive_sel_1v8; 65 + } 66 + 67 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_CLK_DRIVE_SEL, 68 + 0xFF, driving[drive_sel][0]); 69 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_CMD_DRIVE_SEL, 70 + 0xFF, driving[drive_sel][1]); 71 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_DAT_DRIVE_SEL, 72 + 0xFF, driving[drive_sel][2]); 73 + } 74 + 75 + static void rtsx_base_fetch_vendor_settings(struct rtsx_pcr *pcr) 76 + { 77 + u32 reg; 78 + 79 + rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg); 80 + pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg); 81 + 82 + if (!rtsx_vendor_setting_valid(reg)) { 83 + pcr_dbg(pcr, "skip fetch vendor setting\n"); 84 + return; 85 + } 86 + 87 + pcr->aspm_en = rtsx_reg_to_aspm(reg); 88 + pcr->sd30_drive_sel_1v8 = rtsx_reg_to_sd30_drive_sel_1v8(reg); 89 + pcr->card_drive_sel &= 0x3F; 90 + pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg); 91 + 92 + rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg); 93 + pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg); 94 + pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg); 95 + if (rtsx_reg_check_reverse_socket(reg)) 96 + pcr->flags |= PCR_REVERSE_SOCKET; 97 + } 98 + 99 + static void rtsx_base_force_power_down(struct rtsx_pcr *pcr, u8 pm_state) 100 + { 101 + /* Set relink_time to 0 */ 102 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 1, MASK_8_BIT_DEF, 0); 103 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 2, MASK_8_BIT_DEF, 0); 104 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 105 + RELINK_TIME_MASK, 0); 106 + 107 + if (pm_state == HOST_ENTER_S3) 108 + rtsx_pci_write_register(pcr, pcr->reg_pm_ctrl3, 109 + D3_DELINK_MODE_EN, D3_DELINK_MODE_EN); 110 + 111 + rtsx_pci_write_register(pcr, FPDCTL, ALL_POWER_DOWN, ALL_POWER_DOWN); 112 + } 113 + 114 + static int rtsx_base_enable_auto_blink(struct rtsx_pcr *pcr) 115 + { 116 + return rtsx_pci_write_register(pcr, OLT_LED_CTL, 117 + LED_SHINE_MASK, LED_SHINE_EN); 118 + } 119 + 120 + static int rtsx_base_disable_auto_blink(struct rtsx_pcr *pcr) 121 + { 122 + return rtsx_pci_write_register(pcr, OLT_LED_CTL, 123 + LED_SHINE_MASK, LED_SHINE_DISABLE); 124 + } 125 + 126 + static int rts5260_turn_on_led(struct rtsx_pcr *pcr) 127 + { 128 + return rtsx_pci_write_register(pcr, RTS5260_REG_GPIO_CTL0, 129 + RTS5260_REG_GPIO_MASK, RTS5260_REG_GPIO_ON); 130 + } 131 + 132 + static int rts5260_turn_off_led(struct rtsx_pcr *pcr) 133 + { 134 + return rtsx_pci_write_register(pcr, RTS5260_REG_GPIO_CTL0, 135 + RTS5260_REG_GPIO_MASK, RTS5260_REG_GPIO_OFF); 136 + } 137 + 138 + /* SD Pull Control Enable: 139 + * SD_DAT[3:0] ==> pull up 140 + * SD_CD ==> pull up 141 + * SD_WP ==> pull up 142 + * SD_CMD ==> pull up 143 + * SD_CLK ==> pull down 144 + */ 145 + static const u32 rts5260_sd_pull_ctl_enable_tbl[] = { 146 + RTSX_REG_PAIR(CARD_PULL_CTL1, 0x66), 147 + RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA), 148 + RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE9), 149 + RTSX_REG_PAIR(CARD_PULL_CTL4, 0xAA), 150 + 0, 151 + }; 152 + 153 + /* SD Pull Control Disable: 154 + * SD_DAT[3:0] ==> pull down 155 + * SD_CD ==> pull up 156 + * SD_WP ==> pull down 157 + * SD_CMD ==> pull down 158 + * SD_CLK ==> pull down 159 + */ 160 + static const u32 rts5260_sd_pull_ctl_disable_tbl[] = { 161 + RTSX_REG_PAIR(CARD_PULL_CTL1, 0x66), 162 + RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55), 163 + RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD5), 164 + RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55), 165 + 0, 166 + }; 167 + 168 + /* MS Pull Control Enable: 169 + * MS CD ==> pull up 170 + * others ==> pull down 171 + */ 172 + static const u32 rts5260_ms_pull_ctl_enable_tbl[] = { 173 + RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55), 174 + RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55), 175 + RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15), 176 + 0, 177 + }; 178 + 179 + /* MS Pull Control Disable: 180 + * MS CD ==> pull up 181 + * others ==> pull down 182 + */ 183 + static const u32 rts5260_ms_pull_ctl_disable_tbl[] = { 184 + RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55), 185 + RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55), 186 + RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15), 187 + 0, 188 + }; 189 + 190 + static int sd_set_sample_push_timing_sd30(struct rtsx_pcr *pcr) 191 + { 192 + rtsx_pci_write_register(pcr, SD_CFG1, SD_MODE_SELECT_MASK 193 + | SD_ASYNC_FIFO_NOT_RST, SD_30_MODE | SD_ASYNC_FIFO_NOT_RST); 194 + rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, CLK_LOW_FREQ); 195 + rtsx_pci_write_register(pcr, CARD_CLK_SOURCE, 0xFF, 196 + CRC_VAR_CLK0 | SD30_FIX_CLK | SAMPLE_VAR_CLK1); 197 + rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, 0); 198 + 199 + return 0; 200 + } 201 + 202 + static int rts5260_card_power_on(struct rtsx_pcr *pcr, int card) 203 + { 204 + int err = 0; 205 + struct rtsx_cr_option *option = &pcr->option; 206 + 207 + if (option->ocp_en) 208 + rtsx_pci_enable_ocp(pcr); 209 + 210 + rtsx_pci_init_cmd(pcr); 211 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_CONFIG2, 212 + DV331812_VDD1, DV331812_VDD1); 213 + err = rtsx_pci_send_cmd(pcr, CMD_TIMEOUT_DEF); 214 + if (err < 0) 215 + return err; 216 + 217 + rtsx_pci_init_cmd(pcr); 218 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_VCC_CFG0, 219 + RTS5260_DVCC_TUNE_MASK, RTS5260_DVCC_33); 220 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_VCC_CFG1, 221 + LDO_POW_SDVDD1_MASK, LDO_POW_SDVDD1_ON); 222 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_CONFIG2, 223 + DV331812_POWERON, DV331812_POWERON); 224 + err = rtsx_pci_send_cmd(pcr, CMD_TIMEOUT_DEF); 225 + 226 + msleep(20); 227 + 228 + if (pcr->extra_caps & EXTRA_CAPS_SD_SDR50 || 229 + pcr->extra_caps & EXTRA_CAPS_SD_SDR104) 230 + sd_set_sample_push_timing_sd30(pcr); 231 + 232 + /* Initialize SD_CFG1 register */ 233 + rtsx_pci_write_register(pcr, SD_CFG1, 0xFF, 234 + SD_CLK_DIVIDE_128 | SD_20_MODE); 235 + 236 + rtsx_pci_write_register(pcr, SD_SAMPLE_POINT_CTL, 237 + 0xFF, SD20_RX_POS_EDGE); 238 + rtsx_pci_write_register(pcr, SD_PUSH_POINT_CTL, 0xFF, 0); 239 + rtsx_pci_write_register(pcr, CARD_STOP, SD_STOP | SD_CLR_ERR, 240 + SD_STOP | SD_CLR_ERR); 241 + 242 + /* Reset SD_CFG3 register */ 243 + rtsx_pci_write_register(pcr, SD_CFG3, SD30_CLK_END_EN, 0); 244 + rtsx_pci_write_register(pcr, REG_SD_STOP_SDCLK_CFG, 245 + SD30_CLK_STOP_CFG_EN | SD30_CLK_STOP_CFG1 | 246 + SD30_CLK_STOP_CFG0, 0); 247 + 248 + rtsx_pci_write_register(pcr, REG_PRE_RW_MODE, EN_INFINITE_MODE, 0); 249 + 250 + return err; 251 + } 252 + 253 + static int rts5260_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage) 254 + { 255 + switch (voltage) { 256 + case OUTPUT_3V3: 257 + rtsx_pci_write_register(pcr, LDO_CONFIG2, 258 + DV331812_VDD1, DV331812_VDD1); 259 + rtsx_pci_write_register(pcr, LDO_DV18_CFG, 260 + DV331812_MASK, DV331812_33); 261 + rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8, 0); 262 + break; 263 + case OUTPUT_1V8: 264 + rtsx_pci_write_register(pcr, LDO_CONFIG2, 265 + DV331812_VDD1, DV331812_VDD1); 266 + rtsx_pci_write_register(pcr, LDO_DV18_CFG, 267 + DV331812_MASK, DV331812_17); 268 + rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8, 269 + SD_IO_USING_1V8); 270 + break; 271 + default: 272 + return -EINVAL; 273 + } 274 + 275 + /* set pad drive */ 276 + rtsx_pci_init_cmd(pcr); 277 + rts5260_fill_driving(pcr, voltage); 278 + return rtsx_pci_send_cmd(pcr, CMD_TIMEOUT_DEF); 279 + } 280 + 281 + static void rts5260_stop_cmd(struct rtsx_pcr *pcr) 282 + { 283 + rtsx_pci_writel(pcr, RTSX_HCBCTLR, STOP_CMD); 284 + rtsx_pci_writel(pcr, RTSX_HDBCTLR, STOP_DMA); 285 + rtsx_pci_write_register(pcr, RTS5260_DMA_RST_CTL_0, 286 + RTS5260_DMA_RST | RTS5260_ADMA3_RST, 287 + RTS5260_DMA_RST | RTS5260_ADMA3_RST); 288 + rtsx_pci_write_register(pcr, RBCTL, RB_FLUSH, RB_FLUSH); 289 + } 290 + 291 + static void rts5260_card_before_power_off(struct rtsx_pcr *pcr) 292 + { 293 + struct rtsx_cr_option *option = &pcr->option; 294 + 295 + rts5260_stop_cmd(pcr); 296 + rts5260_switch_output_voltage(pcr, OUTPUT_3V3); 297 + 298 + if (option->ocp_en) 299 + rtsx_pci_disable_ocp(pcr); 300 + } 301 + 302 + static int rts5260_card_power_off(struct rtsx_pcr *pcr, int card) 303 + { 304 + int err = 0; 305 + 306 + rts5260_card_before_power_off(pcr); 307 + 308 + rtsx_pci_init_cmd(pcr); 309 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_VCC_CFG1, 310 + LDO_POW_SDVDD1_MASK, LDO_POW_SDVDD1_OFF); 311 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_CONFIG2, 312 + DV331812_POWERON, DV331812_POWEROFF); 313 + err = rtsx_pci_send_cmd(pcr, CMD_TIMEOUT_DEF); 314 + 315 + return err; 316 + } 317 + 318 + static void rts5260_init_ocp(struct rtsx_pcr *pcr) 319 + { 320 + struct rtsx_cr_option *option = &pcr->option; 321 + 322 + if (option->ocp_en) { 323 + u8 mask, val; 324 + 325 + rtsx_pci_write_register(pcr, RTS5260_DVCC_CTRL, 326 + RTS5260_DVCC_OCP_EN | 327 + RTS5260_DVCC_OCP_CL_EN, 328 + RTS5260_DVCC_OCP_EN | 329 + RTS5260_DVCC_OCP_CL_EN); 330 + rtsx_pci_write_register(pcr, RTS5260_DVIO_CTRL, 331 + RTS5260_DVIO_OCP_EN | 332 + RTS5260_DVIO_OCP_CL_EN, 333 + RTS5260_DVIO_OCP_EN | 334 + RTS5260_DVIO_OCP_CL_EN); 335 + 336 + rtsx_pci_write_register(pcr, RTS5260_DVCC_CTRL, 337 + RTS5260_DVCC_OCP_THD_MASK, 338 + option->sd_400mA_ocp_thd); 339 + 340 + rtsx_pci_write_register(pcr, RTS5260_DVIO_CTRL, 341 + RTS5260_DVIO_OCP_THD_MASK, 342 + RTS5260_DVIO_OCP_THD_350); 343 + 344 + rtsx_pci_write_register(pcr, RTS5260_DV331812_CFG, 345 + RTS5260_DV331812_OCP_THD_MASK, 346 + RTS5260_DV331812_OCP_THD_210); 347 + 348 + mask = SD_OCP_GLITCH_MASK | SDVIO_OCP_GLITCH_MASK; 349 + val = pcr->hw_param.ocp_glitch; 350 + rtsx_pci_write_register(pcr, REG_OCPGLITCH, mask, val); 351 + 352 + rtsx_pci_enable_ocp(pcr); 353 + } else { 354 + rtsx_pci_write_register(pcr, RTS5260_DVCC_CTRL, 355 + RTS5260_DVCC_OCP_EN | 356 + RTS5260_DVCC_OCP_CL_EN, 0); 357 + rtsx_pci_write_register(pcr, RTS5260_DVIO_CTRL, 358 + RTS5260_DVIO_OCP_EN | 359 + RTS5260_DVIO_OCP_CL_EN, 0); 360 + } 361 + } 362 + 363 + static void rts5260_enable_ocp(struct rtsx_pcr *pcr) 364 + { 365 + u8 val = 0; 366 + 367 + rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, 0); 368 + 369 + val = SD_OCP_INT_EN | SD_DETECT_EN; 370 + val |= SDVIO_OCP_INT_EN | SDVIO_DETECT_EN; 371 + rtsx_pci_write_register(pcr, REG_OCPCTL, 0xFF, val); 372 + rtsx_pci_write_register(pcr, REG_DV3318_OCPCTL, 373 + DV3318_DETECT_EN | DV3318_OCP_INT_EN, 374 + DV3318_DETECT_EN | DV3318_OCP_INT_EN); 375 + } 376 + 377 + static void rts5260_disable_ocp(struct rtsx_pcr *pcr) 378 + { 379 + u8 mask = 0; 380 + 381 + mask = SD_OCP_INT_EN | SD_DETECT_EN; 382 + mask |= SDVIO_OCP_INT_EN | SDVIO_DETECT_EN; 383 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 384 + rtsx_pci_write_register(pcr, REG_DV3318_OCPCTL, 385 + DV3318_DETECT_EN | DV3318_OCP_INT_EN, 0); 386 + 387 + rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN, 388 + OC_POWER_DOWN); 389 + } 390 + 391 + int rts5260_get_ocpstat(struct rtsx_pcr *pcr, u8 *val) 392 + { 393 + return rtsx_pci_read_register(pcr, REG_OCPSTAT, val); 394 + } 395 + 396 + int rts5260_get_ocpstat2(struct rtsx_pcr *pcr, u8 *val) 397 + { 398 + return rtsx_pci_read_register(pcr, REG_DV3318_OCPSTAT, val); 399 + } 400 + 401 + void rts5260_clear_ocpstat(struct rtsx_pcr *pcr) 402 + { 403 + u8 mask = 0; 404 + u8 val = 0; 405 + 406 + mask = SD_OCP_INT_CLR | SD_OC_CLR; 407 + mask |= SDVIO_OCP_INT_CLR | SDVIO_OC_CLR; 408 + val = SD_OCP_INT_CLR | SD_OC_CLR; 409 + val |= SDVIO_OCP_INT_CLR | SDVIO_OC_CLR; 410 + 411 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, val); 412 + rtsx_pci_write_register(pcr, REG_DV3318_OCPCTL, 413 + DV3318_OCP_INT_CLR | DV3318_OCP_CLR, 414 + DV3318_OCP_INT_CLR | DV3318_OCP_CLR); 415 + udelay(10); 416 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 417 + rtsx_pci_write_register(pcr, REG_DV3318_OCPCTL, 418 + DV3318_OCP_INT_CLR | DV3318_OCP_CLR, 0); 419 + } 420 + 421 + void rts5260_process_ocp(struct rtsx_pcr *pcr) 422 + { 423 + if (!pcr->option.ocp_en) 424 + return; 425 + 426 + rtsx_pci_get_ocpstat(pcr, &pcr->ocp_stat); 427 + rts5260_get_ocpstat2(pcr, &pcr->ocp_stat2); 428 + if (pcr->card_exist & SD_EXIST) 429 + rtsx_sd_power_off_card3v3(pcr); 430 + else if (pcr->card_exist & MS_EXIST) 431 + rtsx_ms_power_off_card3v3(pcr); 432 + 433 + if (!(pcr->card_exist & MS_EXIST) && !(pcr->card_exist & SD_EXIST)) { 434 + if ((pcr->ocp_stat & (SD_OC_NOW | SD_OC_EVER | 435 + SDVIO_OC_NOW | SDVIO_OC_EVER)) || 436 + (pcr->ocp_stat2 & (DV3318_OCP_NOW | DV3318_OCP_EVER))) 437 + rtsx_pci_clear_ocpstat(pcr); 438 + pcr->ocp_stat = 0; 439 + pcr->ocp_stat2 = 0; 440 + } 441 + 442 + if ((pcr->ocp_stat & (SD_OC_NOW | SD_OC_EVER | 443 + SDVIO_OC_NOW | SDVIO_OC_EVER)) || 444 + (pcr->ocp_stat2 & (DV3318_OCP_NOW | DV3318_OCP_EVER))) { 445 + if (pcr->card_exist & SD_EXIST) 446 + rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, 0); 447 + else if (pcr->card_exist & MS_EXIST) 448 + rtsx_pci_write_register(pcr, CARD_OE, MS_OUTPUT_EN, 0); 449 + } 450 + } 451 + 452 + int rts5260_init_hw(struct rtsx_pcr *pcr) 453 + { 454 + int err; 455 + 456 + rtsx_pci_init_ocp(pcr); 457 + 458 + rtsx_pci_init_cmd(pcr); 459 + 460 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, L1SUB_CONFIG1, 461 + AUX_CLK_ACTIVE_SEL_MASK, MAC_CKSW_DONE); 462 + /* Rest L1SUB Config */ 463 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, L1SUB_CONFIG3, 0xFF, 0x00); 464 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PM_CLK_FORCE_CTL, 465 + CLK_PM_EN, CLK_PM_EN); 466 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWD_SUSPEND_EN, 0xFF, 0xFF); 467 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL, 468 + PWR_GATE_EN, PWR_GATE_EN); 469 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, REG_VREF, 470 + PWD_SUSPND_EN, PWD_SUSPND_EN); 471 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, RBCTL, 472 + U_AUTO_DMA_EN_MASK, U_AUTO_DMA_DISABLE); 473 + 474 + if (pcr->flags & PCR_REVERSE_SOCKET) 475 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0); 476 + else 477 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80); 478 + 479 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OBFF_CFG, 480 + OBFF_EN_MASK, OBFF_DISABLE); 481 + 482 + err = rtsx_pci_send_cmd(pcr, CMD_TIMEOUT_DEF); 483 + if (err < 0) 484 + return err; 485 + 486 + return 0; 487 + } 488 + 489 + static void rts5260_pwr_saving_setting(struct rtsx_pcr *pcr) 490 + { 491 + int lss_l1_1, lss_l1_2; 492 + 493 + lss_l1_1 = rtsx_check_dev_flag(pcr, ASPM_L1_1_EN) 494 + | rtsx_check_dev_flag(pcr, PM_L1_1_EN); 495 + lss_l1_2 = rtsx_check_dev_flag(pcr, ASPM_L1_2_EN) 496 + | rtsx_check_dev_flag(pcr, PM_L1_2_EN); 497 + 498 + if (lss_l1_2) { 499 + pcr_dbg(pcr, "Set parameters for L1.2."); 500 + rtsx_pci_write_register(pcr, PWR_GLOBAL_CTRL, 501 + 0xFF, PCIE_L1_2_EN); 502 + rtsx_pci_write_register(pcr, PWR_FE_CTL, 503 + 0xFF, PCIE_L1_2_PD_FE_EN); 504 + } else if (lss_l1_1) { 505 + pcr_dbg(pcr, "Set parameters for L1.1."); 506 + rtsx_pci_write_register(pcr, PWR_GLOBAL_CTRL, 507 + 0xFF, PCIE_L1_1_EN); 508 + rtsx_pci_write_register(pcr, PWR_FE_CTL, 509 + 0xFF, PCIE_L1_1_PD_FE_EN); 510 + } else { 511 + pcr_dbg(pcr, "Set parameters for L1."); 512 + rtsx_pci_write_register(pcr, PWR_GLOBAL_CTRL, 513 + 0xFF, PCIE_L1_0_EN); 514 + rtsx_pci_write_register(pcr, PWR_FE_CTL, 515 + 0xFF, PCIE_L1_0_PD_FE_EN); 516 + } 517 + 518 + rtsx_pci_write_register(pcr, CFG_L1_0_PCIE_DPHY_RET_VALUE, 519 + 0xFF, CFG_L1_0_RET_VALUE_DEFAULT); 520 + rtsx_pci_write_register(pcr, CFG_L1_0_PCIE_MAC_RET_VALUE, 521 + 0xFF, CFG_L1_0_RET_VALUE_DEFAULT); 522 + rtsx_pci_write_register(pcr, CFG_L1_0_CRC_SD30_RET_VALUE, 523 + 0xFF, CFG_L1_0_RET_VALUE_DEFAULT); 524 + rtsx_pci_write_register(pcr, CFG_L1_0_CRC_SD40_RET_VALUE, 525 + 0xFF, CFG_L1_0_RET_VALUE_DEFAULT); 526 + rtsx_pci_write_register(pcr, CFG_L1_0_SYS_RET_VALUE, 527 + 0xFF, CFG_L1_0_RET_VALUE_DEFAULT); 528 + /*Option cut APHY*/ 529 + rtsx_pci_write_register(pcr, CFG_PCIE_APHY_OFF_0, 530 + 0xFF, CFG_PCIE_APHY_OFF_0_DEFAULT); 531 + rtsx_pci_write_register(pcr, CFG_PCIE_APHY_OFF_1, 532 + 0xFF, CFG_PCIE_APHY_OFF_1_DEFAULT); 533 + rtsx_pci_write_register(pcr, CFG_PCIE_APHY_OFF_2, 534 + 0xFF, CFG_PCIE_APHY_OFF_2_DEFAULT); 535 + rtsx_pci_write_register(pcr, CFG_PCIE_APHY_OFF_3, 536 + 0xFF, CFG_PCIE_APHY_OFF_3_DEFAULT); 537 + /*CDR DEC*/ 538 + rtsx_pci_write_register(pcr, PWC_CDR, 0xFF, PWC_CDR_DEFAULT); 539 + /*PWMPFM*/ 540 + rtsx_pci_write_register(pcr, CFG_LP_FPWM_VALUE, 541 + 0xFF, CFG_LP_FPWM_VALUE_DEFAULT); 542 + /*No Power Saving WA*/ 543 + rtsx_pci_write_register(pcr, CFG_L1_0_CRC_MISC_RET_VALUE, 544 + 0xFF, CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT); 545 + } 546 + 547 + static void rts5260_init_from_cfg(struct rtsx_pcr *pcr) 548 + { 549 + struct rtsx_cr_option *option = &pcr->option; 550 + u32 lval; 551 + 552 + rtsx_pci_read_config_dword(pcr, PCR_ASPM_SETTING_5260, &lval); 553 + 554 + if (lval & ASPM_L1_1_EN_MASK) 555 + rtsx_set_dev_flag(pcr, ASPM_L1_1_EN); 556 + 557 + if (lval & ASPM_L1_2_EN_MASK) 558 + rtsx_set_dev_flag(pcr, ASPM_L1_2_EN); 559 + 560 + if (lval & PM_L1_1_EN_MASK) 561 + rtsx_set_dev_flag(pcr, PM_L1_1_EN); 562 + 563 + if (lval & PM_L1_2_EN_MASK) 564 + rtsx_set_dev_flag(pcr, PM_L1_2_EN); 565 + 566 + rts5260_pwr_saving_setting(pcr); 567 + 568 + if (option->ltr_en) { 569 + u16 val; 570 + 571 + pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); 572 + if (val & PCI_EXP_DEVCTL2_LTR_EN) { 573 + option->ltr_enabled = true; 574 + option->ltr_active = true; 575 + rtsx_set_ltr_latency(pcr, option->ltr_active_latency); 576 + } else { 577 + option->ltr_enabled = false; 578 + } 579 + } 580 + 581 + if (rtsx_check_dev_flag(pcr, ASPM_L1_1_EN | ASPM_L1_2_EN 582 + | PM_L1_1_EN | PM_L1_2_EN)) 583 + option->force_clkreq_0 = false; 584 + else 585 + option->force_clkreq_0 = true; 586 + } 587 + 588 + static int rts5260_extra_init_hw(struct rtsx_pcr *pcr) 589 + { 590 + struct rtsx_cr_option *option = &pcr->option; 591 + 592 + /* Set mcu_cnt to 7 to ensure data can be sampled properly */ 593 + rtsx_pci_write_register(pcr, 0xFC03, 0x7F, 0x07); 594 + rtsx_pci_write_register(pcr, SSC_DIV_N_0, 0xFF, 0x5D); 595 + 596 + rts5260_init_from_cfg(pcr); 597 + 598 + /* force no MDIO*/ 599 + rtsx_pci_write_register(pcr, RTS5260_AUTOLOAD_CFG4, 600 + 0xFF, RTS5260_MIMO_DISABLE); 601 + /*Modify SDVCC Tune Default Parameters!*/ 602 + rtsx_pci_write_register(pcr, LDO_VCC_CFG0, 603 + RTS5260_DVCC_TUNE_MASK, RTS5260_DVCC_33); 604 + 605 + rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL); 606 + 607 + rts5260_init_hw(pcr); 608 + 609 + /* 610 + * If u_force_clkreq_0 is enabled, CLKREQ# PIN will be forced 611 + * to drive low, and we forcibly request clock. 612 + */ 613 + if (option->force_clkreq_0) 614 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 615 + FORCE_CLKREQ_DELINK_MASK, FORCE_CLKREQ_LOW); 616 + else 617 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 618 + FORCE_CLKREQ_DELINK_MASK, FORCE_CLKREQ_HIGH); 619 + 620 + return 0; 621 + } 622 + 623 + void rts5260_set_aspm(struct rtsx_pcr *pcr, bool enable) 624 + { 625 + struct rtsx_cr_option *option = &pcr->option; 626 + u8 val = 0; 627 + 628 + if (pcr->aspm_enabled == enable) 629 + return; 630 + 631 + if (option->dev_aspm_mode == DEV_ASPM_DYNAMIC) { 632 + if (enable) 633 + val = pcr->aspm_en; 634 + rtsx_pci_update_cfg_byte(pcr, pcr->pcie_cap + PCI_EXP_LNKCTL, 635 + ASPM_MASK_NEG, val); 636 + } else if (option->dev_aspm_mode == DEV_ASPM_BACKDOOR) { 637 + u8 mask = FORCE_ASPM_VAL_MASK | FORCE_ASPM_CTL0; 638 + 639 + if (!enable) 640 + val = FORCE_ASPM_CTL0; 641 + rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, mask, val); 642 + } 643 + 644 + pcr->aspm_enabled = enable; 645 + } 646 + 647 + static void rts5260_set_l1off_cfg_sub_d0(struct rtsx_pcr *pcr, int active) 648 + { 649 + struct rtsx_cr_option *option = &pcr->option; 650 + u32 interrupt = rtsx_pci_readl(pcr, RTSX_BIPR); 651 + int card_exist = (interrupt & SD_EXIST) | (interrupt & MS_EXIST); 652 + int aspm_L1_1, aspm_L1_2; 653 + u8 val = 0; 654 + 655 + aspm_L1_1 = rtsx_check_dev_flag(pcr, ASPM_L1_1_EN); 656 + aspm_L1_2 = rtsx_check_dev_flag(pcr, ASPM_L1_2_EN); 657 + 658 + if (active) { 659 + /* run, latency: 60us */ 660 + if (aspm_L1_1) 661 + val = option->ltr_l1off_snooze_sspwrgate; 662 + } else { 663 + /* l1off, latency: 300us */ 664 + if (aspm_L1_2) 665 + val = option->ltr_l1off_sspwrgate; 666 + } 667 + 668 + if (aspm_L1_1 || aspm_L1_2) { 669 + if (rtsx_check_dev_flag(pcr, 670 + LTR_L1SS_PWR_GATE_CHECK_CARD_EN)) { 671 + if (card_exist) 672 + val &= ~L1OFF_MBIAS2_EN_5250; 673 + else 674 + val |= L1OFF_MBIAS2_EN_5250; 675 + } 676 + } 677 + rtsx_set_l1off_sub(pcr, val); 678 + } 679 + 680 + static const struct pcr_ops rts5260_pcr_ops = { 681 + .fetch_vendor_settings = rtsx_base_fetch_vendor_settings, 682 + .turn_on_led = rts5260_turn_on_led, 683 + .turn_off_led = rts5260_turn_off_led, 684 + .extra_init_hw = rts5260_extra_init_hw, 685 + .enable_auto_blink = rtsx_base_enable_auto_blink, 686 + .disable_auto_blink = rtsx_base_disable_auto_blink, 687 + .card_power_on = rts5260_card_power_on, 688 + .card_power_off = rts5260_card_power_off, 689 + .switch_output_voltage = rts5260_switch_output_voltage, 690 + .force_power_down = rtsx_base_force_power_down, 691 + .stop_cmd = rts5260_stop_cmd, 692 + .set_aspm = rts5260_set_aspm, 693 + .set_l1off_cfg_sub_d0 = rts5260_set_l1off_cfg_sub_d0, 694 + .enable_ocp = rts5260_enable_ocp, 695 + .disable_ocp = rts5260_disable_ocp, 696 + .init_ocp = rts5260_init_ocp, 697 + .process_ocp = rts5260_process_ocp, 698 + .get_ocpstat = rts5260_get_ocpstat, 699 + .clear_ocpstat = rts5260_clear_ocpstat, 700 + }; 701 + 702 + void rts5260_init_params(struct rtsx_pcr *pcr) 703 + { 704 + struct rtsx_cr_option *option = &pcr->option; 705 + struct rtsx_hw_param *hw_param = &pcr->hw_param; 706 + 707 + pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104; 708 + pcr->num_slots = 2; 709 + 710 + pcr->flags = 0; 711 + pcr->card_drive_sel = RTSX_CARD_DRIVE_DEFAULT; 712 + pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_B; 713 + pcr->sd30_drive_sel_3v3 = CFG_DRIVER_TYPE_B; 714 + pcr->aspm_en = ASPM_L1_EN; 715 + pcr->tx_initial_phase = SET_CLOCK_PHASE(1, 29, 16); 716 + pcr->rx_initial_phase = SET_CLOCK_PHASE(24, 6, 5); 717 + 718 + pcr->ic_version = rts5260_get_ic_version(pcr); 719 + pcr->sd_pull_ctl_enable_tbl = rts5260_sd_pull_ctl_enable_tbl; 720 + pcr->sd_pull_ctl_disable_tbl = rts5260_sd_pull_ctl_disable_tbl; 721 + pcr->ms_pull_ctl_enable_tbl = rts5260_ms_pull_ctl_enable_tbl; 722 + pcr->ms_pull_ctl_disable_tbl = rts5260_ms_pull_ctl_disable_tbl; 723 + 724 + pcr->reg_pm_ctrl3 = RTS524A_PM_CTRL3; 725 + 726 + pcr->ops = &rts5260_pcr_ops; 727 + 728 + option->dev_flags = (LTR_L1SS_PWR_GATE_CHECK_CARD_EN 729 + | LTR_L1SS_PWR_GATE_EN); 730 + option->ltr_en = true; 731 + 732 + /* init latency of active, idle, L1OFF to 60us, 300us, 3ms */ 733 + option->ltr_active_latency = LTR_ACTIVE_LATENCY_DEF; 734 + option->ltr_idle_latency = LTR_IDLE_LATENCY_DEF; 735 + option->ltr_l1off_latency = LTR_L1OFF_LATENCY_DEF; 736 + option->dev_aspm_mode = DEV_ASPM_DYNAMIC; 737 + option->l1_snooze_delay = L1_SNOOZE_DELAY_DEF; 738 + option->ltr_l1off_sspwrgate = LTR_L1OFF_SSPWRGATE_5250_DEF; 739 + option->ltr_l1off_snooze_sspwrgate = 740 + LTR_L1OFF_SNOOZE_SSPWRGATE_5250_DEF; 741 + 742 + option->ocp_en = 1; 743 + if (option->ocp_en) 744 + hw_param->interrupt_en |= SD_OC_INT_EN; 745 + hw_param->ocp_glitch = SD_OCP_GLITCH_10M | SDVIO_OCP_GLITCH_800U; 746 + option->sd_400mA_ocp_thd = RTS5260_DVCC_OCP_THD_550; 747 + option->sd_800mA_ocp_thd = RTS5260_DVCC_OCP_THD_970; 748 + }
+45
drivers/misc/cardreader/rts5260.h
··· 1 + #ifndef __RTS5260_H__ 2 + #define __RTS5260_H__ 3 + 4 + #define RTS5260_DVCC_CTRL 0xFF73 5 + #define RTS5260_DVCC_OCP_EN (0x01 << 7) 6 + #define RTS5260_DVCC_OCP_THD_MASK (0x07 << 4) 7 + #define RTS5260_DVCC_POWERON (0x01 << 3) 8 + #define RTS5260_DVCC_OCP_CL_EN (0x01 << 2) 9 + 10 + #define RTS5260_DVIO_CTRL 0xFF75 11 + #define RTS5260_DVIO_OCP_EN (0x01 << 7) 12 + #define RTS5260_DVIO_OCP_THD_MASK (0x07 << 4) 13 + #define RTS5260_DVIO_POWERON (0x01 << 3) 14 + #define RTS5260_DVIO_OCP_CL_EN (0x01 << 2) 15 + 16 + #define RTS5260_DV331812_CFG 0xFF71 17 + #define RTS5260_DV331812_OCP_EN (0x01 << 7) 18 + #define RTS5260_DV331812_OCP_THD_MASK (0x07 << 4) 19 + #define RTS5260_DV331812_POWERON (0x01 << 3) 20 + #define RTS5260_DV331812_SEL (0x01 << 2) 21 + #define RTS5260_DV331812_VDD1 (0x01 << 2) 22 + #define RTS5260_DV331812_VDD2 (0x00 << 2) 23 + 24 + #define RTS5260_DV331812_OCP_THD_120 (0x00 << 4) 25 + #define RTS5260_DV331812_OCP_THD_140 (0x01 << 4) 26 + #define RTS5260_DV331812_OCP_THD_160 (0x02 << 4) 27 + #define RTS5260_DV331812_OCP_THD_180 (0x03 << 4) 28 + #define RTS5260_DV331812_OCP_THD_210 (0x04 << 4) 29 + #define RTS5260_DV331812_OCP_THD_240 (0x05 << 4) 30 + #define RTS5260_DV331812_OCP_THD_270 (0x06 << 4) 31 + #define RTS5260_DV331812_OCP_THD_300 (0x07 << 4) 32 + 33 + #define RTS5260_DVIO_OCP_THD_250 (0x00 << 4) 34 + #define RTS5260_DVIO_OCP_THD_300 (0x01 << 4) 35 + #define RTS5260_DVIO_OCP_THD_350 (0x02 << 4) 36 + #define RTS5260_DVIO_OCP_THD_400 (0x03 << 4) 37 + #define RTS5260_DVIO_OCP_THD_450 (0x04 << 4) 38 + #define RTS5260_DVIO_OCP_THD_500 (0x05 << 4) 39 + #define RTS5260_DVIO_OCP_THD_550 (0x06 << 4) 40 + #define RTS5260_DVIO_OCP_THD_600 (0x07 << 4) 41 + 42 + #define RTS5260_DVCC_OCP_THD_550 (0x00 << 4) 43 + #define RTS5260_DVCC_OCP_THD_970 (0x05 << 4) 44 + 45 + #endif
+2 -2
drivers/mmc/host/Kconfig
··· 838 838 839 839 config MMC_REALTEK_PCI 840 840 tristate "Realtek PCI-E SD/MMC Card Interface Driver" 841 - depends on MFD_RTSX_PCI 841 + depends on MISC_RTSX_PCI 842 842 help 843 843 Say Y here to include driver code to support SD/MMC card interface 844 844 of Realtek PCI-E card reader 845 845 846 846 config MMC_REALTEK_USB 847 847 tristate "Realtek USB SD/MMC Card Interface Driver" 848 - depends on MFD_RTSX_USB 848 + depends on MISC_RTSX_USB 849 849 help 850 850 Say Y here to include driver code to support SD/MMC card interface 851 851 of Realtek RTS5129/39 series card reader
+1 -1
drivers/mmc/host/rtsx_pci_sdmmc.c
··· 30 30 #include <linux/mmc/sd.h> 31 31 #include <linux/mmc/sdio.h> 32 32 #include <linux/mmc/card.h> 33 - #include <linux/mfd/rtsx_pci.h> 33 + #include <linux/rtsx_pci.h> 34 34 #include <asm/unaligned.h> 35 35 36 36 struct realtek_pci_sdmmc {
+1 -1
drivers/mmc/host/rtsx_usb_sdmmc.c
··· 31 31 #include <linux/scatterlist.h> 32 32 #include <linux/pm_runtime.h> 33 33 34 - #include <linux/mfd/rtsx_usb.h> 34 + #include <linux/rtsx_usb.h> 35 35 #include <asm/unaligned.h> 36 36 37 37 #if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \
+2 -8
drivers/platform/chrome/Kconfig
··· 38 38 If you have a supported Chromebook, choose Y or M here. 39 39 The module will be called chromeos_pstore. 40 40 41 - config CROS_EC_CHARDEV 42 - tristate "Chrome OS Embedded Controller userspace device interface" 43 - depends on MFD_CROS_EC 44 - ---help--- 45 - This driver adds support to talk with the ChromeOS EC from userspace. 46 - 47 - If you have a supported Chromebook, choose Y or M here. 48 - The module will be called cros_ec_dev. 41 + config CROS_EC_CTL 42 + tristate 49 43 50 44 config CROS_EC_LPC 51 45 tristate "ChromeOS Embedded Controller (LPC)"
+3 -4
drivers/platform/chrome/Makefile
··· 2 2 3 3 obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o 4 4 obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o 5 - cros_ec_devs-objs := cros_ec_dev.o cros_ec_sysfs.o \ 6 - cros_ec_lightbar.o cros_ec_vbc.o \ 7 - cros_ec_debugfs.o 8 - obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_devs.o 5 + cros_ec_ctl-objs := cros_ec_sysfs.o cros_ec_lightbar.o \ 6 + cros_ec_vbc.o cros_ec_debugfs.o 7 + obj-$(CONFIG_CROS_EC_CTL) += cros_ec_ctl.o 9 8 cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_reg.o 10 9 cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o 11 10 obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o
+2 -3
drivers/platform/chrome/cros_ec_debugfs.c
··· 29 29 #include <linux/slab.h> 30 30 #include <linux/wait.h> 31 31 32 - #include "cros_ec_dev.h" 33 - #include "cros_ec_debugfs.h" 34 - 35 32 #define LOG_SHIFT 14 36 33 #define LOG_SIZE (1 << LOG_SHIFT) 37 34 #define LOG_POLL_SEC 10 ··· 387 390 debugfs_remove_recursive(debug_info->dir); 388 391 return ret; 389 392 } 393 + EXPORT_SYMBOL(cros_ec_debugfs_init); 390 394 391 395 void cros_ec_debugfs_remove(struct cros_ec_dev *ec) 392 396 { ··· 397 399 debugfs_remove_recursive(ec->debug_info->dir); 398 400 cros_ec_cleanup_console_log(ec->debug_info); 399 401 } 402 + EXPORT_SYMBOL(cros_ec_debugfs_remove);
-27
drivers/platform/chrome/cros_ec_debugfs.h
··· 1 - /* 2 - * Copyright 2015 Google, Inc. 3 - * 4 - * This program is free software; you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License as published by 6 - * the Free Software Foundation; either version 2 of the License, or 7 - * (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 - */ 17 - 18 - #ifndef _DRV_CROS_EC_DEBUGFS_H_ 19 - #define _DRV_CROS_EC_DEBUGFS_H_ 20 - 21 - #include "cros_ec_dev.h" 22 - 23 - /* debugfs stuff */ 24 - int cros_ec_debugfs_init(struct cros_ec_dev *ec); 25 - void cros_ec_debugfs_remove(struct cros_ec_dev *ec); 26 - 27 - #endif /* _DRV_CROS_EC_DEBUGFS_H_ */
+5 -3
drivers/platform/chrome/cros_ec_dev.c drivers/mfd/cros_ec_dev.c
··· 25 25 #include <linux/slab.h> 26 26 #include <linux/uaccess.h> 27 27 28 - #include "cros_ec_debugfs.h" 29 28 #include "cros_ec_dev.h" 29 + 30 + #define DRV_NAME "cros-ec-dev" 30 31 31 32 /* Device variables */ 32 33 #define CROS_MAX_DEV 128 ··· 462 461 } 463 462 464 463 static const struct platform_device_id cros_ec_id[] = { 465 - { "cros-ec-ctl", 0 }, 464 + { DRV_NAME, 0 }, 466 465 { /* sentinel */ }, 467 466 }; 468 467 MODULE_DEVICE_TABLE(platform, cros_ec_id); ··· 494 493 495 494 static struct platform_driver cros_ec_dev_driver = { 496 495 .driver = { 497 - .name = "cros-ec-ctl", 496 + .name = DRV_NAME, 498 497 .pm = &cros_ec_dev_pm_ops, 499 498 }, 500 499 .probe = ec_device_probe, ··· 545 544 module_init(cros_ec_dev_init); 546 545 module_exit(cros_ec_dev_exit); 547 546 547 + MODULE_ALIAS("platform:" DRV_NAME); 548 548 MODULE_AUTHOR("Bill Richardson <wfrichar@chromium.org>"); 549 549 MODULE_DESCRIPTION("Userspace interface to the Chrome OS Embedded Controller"); 550 550 MODULE_VERSION("1.0");
drivers/platform/chrome/cros_ec_dev.h drivers/mfd/cros_ec_dev.h
+4 -2
drivers/platform/chrome/cros_ec_lightbar.c
··· 33 33 #include <linux/uaccess.h> 34 34 #include <linux/slab.h> 35 35 36 - #include "cros_ec_dev.h" 37 - 38 36 /* Rate-limit the lightbar interface to prevent DoS. */ 39 37 static unsigned long lb_interval_jiffies = 50 * HZ / 1000; 40 38 ··· 412 414 413 415 return ret; 414 416 } 417 + EXPORT_SYMBOL(lb_manual_suspend_ctrl); 415 418 416 419 int lb_suspend(struct cros_ec_dev *ec) 417 420 { ··· 421 422 422 423 return lb_send_empty_cmd(ec, LIGHTBAR_CMD_SUSPEND); 423 424 } 425 + EXPORT_SYMBOL(lb_suspend); 424 426 425 427 int lb_resume(struct cros_ec_dev *ec) 426 428 { ··· 430 430 431 431 return lb_send_empty_cmd(ec, LIGHTBAR_CMD_RESUME); 432 432 } 433 + EXPORT_SYMBOL(lb_resume); 433 434 434 435 static ssize_t sequence_store(struct device *dev, struct device_attribute *attr, 435 436 const char *buf, size_t count) ··· 623 622 .attrs = __lb_cmds_attrs, 624 623 .is_visible = cros_ec_lightbar_attrs_are_visible, 625 624 }; 625 + EXPORT_SYMBOL(cros_ec_lightbar_attr_group);
+3 -2
drivers/platform/chrome/cros_ec_sysfs.c
··· 34 34 #include <linux/types.h> 35 35 #include <linux/uaccess.h> 36 36 37 - #include "cros_ec_dev.h" 38 - 39 37 /* Accessor functions */ 40 38 41 39 static ssize_t show_ec_reboot(struct device *dev, ··· 292 294 struct attribute_group cros_ec_attr_group = { 293 295 .attrs = __ec_attrs, 294 296 }; 297 + EXPORT_SYMBOL(cros_ec_attr_group); 295 298 299 + MODULE_LICENSE("GPL"); 300 + MODULE_DESCRIPTION("ChromeOS EC control driver");
+1
drivers/platform/chrome/cros_ec_vbc.c
··· 135 135 .bin_attrs = cros_ec_vbc_bin_attrs, 136 136 .is_bin_visible = cros_ec_vbc_is_visible, 137 137 }; 138 + EXPORT_SYMBOL(cros_ec_vbc_attr_group);
+29 -2
drivers/tty/serdev/core.c
··· 132 132 } 133 133 EXPORT_SYMBOL_GPL(serdev_device_close); 134 134 135 + static void devm_serdev_device_release(struct device *dev, void *dr) 136 + { 137 + serdev_device_close(*(struct serdev_device **)dr); 138 + } 139 + 140 + int devm_serdev_device_open(struct device *dev, struct serdev_device *serdev) 141 + { 142 + struct serdev_device **dr; 143 + int ret; 144 + 145 + dr = devres_alloc(devm_serdev_device_release, sizeof(*dr), GFP_KERNEL); 146 + if (!dr) 147 + return -ENOMEM; 148 + 149 + ret = serdev_device_open(serdev); 150 + if (ret) { 151 + devres_free(dr); 152 + return ret; 153 + } 154 + 155 + *dr = serdev; 156 + devres_add(dev, dr); 157 + 158 + return 0; 159 + } 160 + EXPORT_SYMBOL_GPL(devm_serdev_device_open); 161 + 135 162 void serdev_device_write_wakeup(struct serdev_device *serdev) 136 163 { 137 164 complete(&serdev->write_comp); ··· 295 268 static int serdev_drv_remove(struct device *dev) 296 269 { 297 270 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); 298 - 299 - sdrv->remove(to_serdev_device(dev)); 271 + if (sdrv->remove) 272 + sdrv->remove(to_serdev_device(dev)); 300 273 return 0; 301 274 } 302 275
+7
drivers/watchdog/Kconfig
··· 223 223 To compile this driver as a module, choose M here: the 224 224 module will be called ziirave_wdt. 225 225 226 + config RAVE_SP_WATCHDOG 227 + tristate "RAVE SP Watchdog timer" 228 + depends on RAVE_SP_CORE 229 + select WATCHDOG_CORE 230 + help 231 + Support for the watchdog on RAVE SP device. 232 + 226 233 # ALPHA Architecture 227 234 228 235 # ARM Architecture
+1
drivers/watchdog/Makefile
··· 224 224 obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o 225 225 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o 226 226 obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o 227 + obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+337
drivers/watchdog/rave-sp-wdt.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + 3 + /* 4 + * Driver for watchdog aspect of for Zodiac Inflight Innovations RAVE 5 + * Supervisory Processor(SP) MCU 6 + * 7 + * Copyright (C) 2017 Zodiac Inflight Innovation 8 + * 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/kernel.h> 13 + #include <linux/mfd/rave-sp.h> 14 + #include <linux/module.h> 15 + #include <linux/nvmem-consumer.h> 16 + #include <linux/of_device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/reboot.h> 19 + #include <linux/slab.h> 20 + #include <linux/watchdog.h> 21 + 22 + enum { 23 + RAVE_SP_RESET_BYTE = 1, 24 + RAVE_SP_RESET_REASON_NORMAL = 0, 25 + RAVE_SP_RESET_DELAY_MS = 500, 26 + }; 27 + 28 + /** 29 + * struct rave_sp_wdt_variant - RAVE SP watchdog variant 30 + * 31 + * @max_timeout: Largest possible watchdog timeout setting 32 + * @min_timeout: Smallest possible watchdog timeout setting 33 + * 34 + * @configure: Function to send configuration command 35 + * @restart: Function to send "restart" command 36 + */ 37 + struct rave_sp_wdt_variant { 38 + unsigned int max_timeout; 39 + unsigned int min_timeout; 40 + 41 + int (*configure)(struct watchdog_device *, bool); 42 + int (*restart)(struct watchdog_device *); 43 + }; 44 + 45 + /** 46 + * struct rave_sp_wdt - RAVE SP watchdog 47 + * 48 + * @wdd: Underlying watchdog device 49 + * @sp: Pointer to parent RAVE SP device 50 + * @variant: Device specific variant information 51 + * @reboot_notifier: Reboot notifier implementing machine reset 52 + */ 53 + struct rave_sp_wdt { 54 + struct watchdog_device wdd; 55 + struct rave_sp *sp; 56 + const struct rave_sp_wdt_variant *variant; 57 + struct notifier_block reboot_notifier; 58 + }; 59 + 60 + static struct rave_sp_wdt *to_rave_sp_wdt(struct watchdog_device *wdd) 61 + { 62 + return container_of(wdd, struct rave_sp_wdt, wdd); 63 + } 64 + 65 + static int rave_sp_wdt_exec(struct watchdog_device *wdd, void *data, 66 + size_t data_size) 67 + { 68 + return rave_sp_exec(to_rave_sp_wdt(wdd)->sp, 69 + data, data_size, NULL, 0); 70 + } 71 + 72 + static int rave_sp_wdt_legacy_configure(struct watchdog_device *wdd, bool on) 73 + { 74 + u8 cmd[] = { 75 + [0] = RAVE_SP_CMD_SW_WDT, 76 + [1] = 0, 77 + [2] = 0, 78 + [3] = on, 79 + [4] = on ? wdd->timeout : 0, 80 + }; 81 + 82 + return rave_sp_wdt_exec(wdd, cmd, sizeof(cmd)); 83 + } 84 + 85 + static int rave_sp_wdt_rdu_configure(struct watchdog_device *wdd, bool on) 86 + { 87 + u8 cmd[] = { 88 + [0] = RAVE_SP_CMD_SW_WDT, 89 + [1] = 0, 90 + [2] = on, 91 + [3] = (u8)wdd->timeout, 92 + [4] = (u8)(wdd->timeout >> 8), 93 + }; 94 + 95 + return rave_sp_wdt_exec(wdd, cmd, sizeof(cmd)); 96 + } 97 + 98 + /** 99 + * rave_sp_wdt_configure - Configure watchdog device 100 + * 101 + * @wdd: Device to configure 102 + * @on: Desired state of the watchdog timer (ON/OFF) 103 + * 104 + * This function configures two aspects of the watchdog timer: 105 + * 106 + * - Wheither it is ON or OFF 107 + * - Its timeout duration 108 + * 109 + * with first aspect specified via function argument and second via 110 + * the value of 'wdd->timeout'. 111 + */ 112 + static int rave_sp_wdt_configure(struct watchdog_device *wdd, bool on) 113 + { 114 + return to_rave_sp_wdt(wdd)->variant->configure(wdd, on); 115 + } 116 + 117 + static int rave_sp_wdt_legacy_restart(struct watchdog_device *wdd) 118 + { 119 + u8 cmd[] = { 120 + [0] = RAVE_SP_CMD_RESET, 121 + [1] = 0, 122 + [2] = RAVE_SP_RESET_BYTE 123 + }; 124 + 125 + return rave_sp_wdt_exec(wdd, cmd, sizeof(cmd)); 126 + } 127 + 128 + static int rave_sp_wdt_rdu_restart(struct watchdog_device *wdd) 129 + { 130 + u8 cmd[] = { 131 + [0] = RAVE_SP_CMD_RESET, 132 + [1] = 0, 133 + [2] = RAVE_SP_RESET_BYTE, 134 + [3] = RAVE_SP_RESET_REASON_NORMAL 135 + }; 136 + 137 + return rave_sp_wdt_exec(wdd, cmd, sizeof(cmd)); 138 + } 139 + 140 + static int rave_sp_wdt_reboot_notifier(struct notifier_block *nb, 141 + unsigned long action, void *data) 142 + { 143 + /* 144 + * Restart handler is called in atomic context which means we 145 + * can't communicate to SP via UART. Luckily for use SP will 146 + * wait 500ms before actually resetting us, so we ask it to do 147 + * so here and let the rest of the system go on wrapping 148 + * things up. 149 + */ 150 + if (action == SYS_DOWN || action == SYS_HALT) { 151 + struct rave_sp_wdt *sp_wd = 152 + container_of(nb, struct rave_sp_wdt, reboot_notifier); 153 + 154 + const int ret = sp_wd->variant->restart(&sp_wd->wdd); 155 + 156 + if (ret < 0) 157 + dev_err(sp_wd->wdd.parent, 158 + "Failed to issue restart command (%d)", ret); 159 + return NOTIFY_OK; 160 + } 161 + 162 + return NOTIFY_DONE; 163 + } 164 + 165 + static int rave_sp_wdt_restart(struct watchdog_device *wdd, 166 + unsigned long action, void *data) 167 + { 168 + /* 169 + * The actual work was done by reboot notifier above. SP 170 + * firmware waits 500 ms before issuing reset, so let's hang 171 + * here for twice that delay and hopefuly we'd never reach 172 + * the return statement. 173 + */ 174 + mdelay(2 * RAVE_SP_RESET_DELAY_MS); 175 + 176 + return -EIO; 177 + } 178 + 179 + static int rave_sp_wdt_start(struct watchdog_device *wdd) 180 + { 181 + int ret; 182 + 183 + ret = rave_sp_wdt_configure(wdd, true); 184 + if (!ret) 185 + set_bit(WDOG_HW_RUNNING, &wdd->status); 186 + 187 + return ret; 188 + } 189 + 190 + static int rave_sp_wdt_stop(struct watchdog_device *wdd) 191 + { 192 + return rave_sp_wdt_configure(wdd, false); 193 + } 194 + 195 + static int rave_sp_wdt_set_timeout(struct watchdog_device *wdd, 196 + unsigned int timeout) 197 + { 198 + wdd->timeout = timeout; 199 + 200 + return rave_sp_wdt_configure(wdd, watchdog_active(wdd)); 201 + } 202 + 203 + static int rave_sp_wdt_ping(struct watchdog_device *wdd) 204 + { 205 + u8 cmd[] = { 206 + [0] = RAVE_SP_CMD_PET_WDT, 207 + [1] = 0, 208 + }; 209 + 210 + return rave_sp_wdt_exec(wdd, cmd, sizeof(cmd)); 211 + } 212 + 213 + static const struct watchdog_info rave_sp_wdt_info = { 214 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 215 + .identity = "RAVE SP Watchdog", 216 + }; 217 + 218 + static const struct watchdog_ops rave_sp_wdt_ops = { 219 + .owner = THIS_MODULE, 220 + .start = rave_sp_wdt_start, 221 + .stop = rave_sp_wdt_stop, 222 + .ping = rave_sp_wdt_ping, 223 + .set_timeout = rave_sp_wdt_set_timeout, 224 + .restart = rave_sp_wdt_restart, 225 + }; 226 + 227 + static const struct rave_sp_wdt_variant rave_sp_wdt_legacy = { 228 + .max_timeout = 255, 229 + .min_timeout = 1, 230 + .configure = rave_sp_wdt_legacy_configure, 231 + .restart = rave_sp_wdt_legacy_restart, 232 + }; 233 + 234 + static const struct rave_sp_wdt_variant rave_sp_wdt_rdu = { 235 + .max_timeout = 180, 236 + .min_timeout = 60, 237 + .configure = rave_sp_wdt_rdu_configure, 238 + .restart = rave_sp_wdt_rdu_restart, 239 + }; 240 + 241 + static const struct of_device_id rave_sp_wdt_of_match[] = { 242 + { 243 + .compatible = "zii,rave-sp-watchdog-legacy", 244 + .data = &rave_sp_wdt_legacy, 245 + }, 246 + { 247 + .compatible = "zii,rave-sp-watchdog", 248 + .data = &rave_sp_wdt_rdu, 249 + }, 250 + { /* sentinel */ } 251 + }; 252 + 253 + static int rave_sp_wdt_probe(struct platform_device *pdev) 254 + { 255 + struct device *dev = &pdev->dev; 256 + struct watchdog_device *wdd; 257 + struct rave_sp_wdt *sp_wd; 258 + struct nvmem_cell *cell; 259 + __le16 timeout = 0; 260 + int ret; 261 + 262 + sp_wd = devm_kzalloc(dev, sizeof(*sp_wd), GFP_KERNEL); 263 + if (!sp_wd) 264 + return -ENOMEM; 265 + 266 + sp_wd->variant = of_device_get_match_data(dev); 267 + sp_wd->sp = dev_get_drvdata(dev->parent); 268 + 269 + wdd = &sp_wd->wdd; 270 + wdd->parent = dev; 271 + wdd->info = &rave_sp_wdt_info; 272 + wdd->ops = &rave_sp_wdt_ops; 273 + wdd->min_timeout = sp_wd->variant->min_timeout; 274 + wdd->max_timeout = sp_wd->variant->max_timeout; 275 + wdd->status = WATCHDOG_NOWAYOUT_INIT_STATUS; 276 + wdd->timeout = 60; 277 + 278 + cell = nvmem_cell_get(dev, "wdt-timeout"); 279 + if (!IS_ERR(cell)) { 280 + size_t len; 281 + void *value = nvmem_cell_read(cell, &len); 282 + 283 + if (!IS_ERR(value)) { 284 + memcpy(&timeout, value, min(len, sizeof(timeout))); 285 + kfree(value); 286 + } 287 + nvmem_cell_put(cell); 288 + } 289 + watchdog_init_timeout(wdd, le16_to_cpu(timeout), dev); 290 + watchdog_set_restart_priority(wdd, 255); 291 + watchdog_stop_on_unregister(wdd); 292 + 293 + sp_wd->reboot_notifier.notifier_call = rave_sp_wdt_reboot_notifier; 294 + ret = devm_register_reboot_notifier(dev, &sp_wd->reboot_notifier); 295 + if (ret) { 296 + dev_err(dev, "Failed to register reboot notifier\n"); 297 + return ret; 298 + } 299 + 300 + /* 301 + * We don't know if watchdog is running now. To be sure, let's 302 + * start it and depend on watchdog core to ping it 303 + */ 304 + wdd->max_hw_heartbeat_ms = wdd->max_timeout * 1000; 305 + ret = rave_sp_wdt_start(wdd); 306 + if (ret) { 307 + dev_err(dev, "Watchdog didn't start\n"); 308 + return ret; 309 + } 310 + 311 + ret = devm_watchdog_register_device(dev, wdd); 312 + if (ret) { 313 + dev_err(dev, "Failed to register watchdog device\n"); 314 + rave_sp_wdt_stop(wdd); 315 + return ret; 316 + } 317 + 318 + return 0; 319 + } 320 + 321 + static struct platform_driver rave_sp_wdt_driver = { 322 + .probe = rave_sp_wdt_probe, 323 + .driver = { 324 + .name = KBUILD_MODNAME, 325 + .of_match_table = rave_sp_wdt_of_match, 326 + }, 327 + }; 328 + 329 + module_platform_driver(rave_sp_wdt_driver); 330 + 331 + MODULE_DEVICE_TABLE(of, rave_sp_wdt_of_match); 332 + MODULE_LICENSE("GPL"); 333 + MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>"); 334 + MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>"); 335 + MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>"); 336 + MODULE_DESCRIPTION("RAVE SP Watchdog driver"); 337 + MODULE_ALIAS("platform:rave-sp-watchdog");
+7
include/linux/crc-ccitt.h
··· 5 5 #include <linux/types.h> 6 6 7 7 extern u16 const crc_ccitt_table[256]; 8 + extern u16 const crc_ccitt_false_table[256]; 8 9 9 10 extern u16 crc_ccitt(u16 crc, const u8 *buffer, size_t len); 11 + extern u16 crc_ccitt_false(u16 crc, const u8 *buffer, size_t len); 10 12 11 13 static inline u16 crc_ccitt_byte(u16 crc, const u8 c) 12 14 { 13 15 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff]; 16 + } 17 + 18 + static inline u16 crc_ccitt_false_byte(u16 crc, const u8 c) 19 + { 20 + return (crc << 8) ^ crc_ccitt_false_table[(crc >> 8) ^ c]; 14 21 } 15 22 16 23 #endif /* _LINUX_CRC_CCITT_H */
-5
include/linux/mfd/axp20x.h
··· 645 645 const struct regmap_irq_chip *regmap_irq_chip; 646 646 }; 647 647 648 - struct axp288_extcon_pdata { 649 - /* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */ 650 - struct gpio_desc *gpio_mux_cntl; 651 - }; 652 - 653 648 /* generic helper function for reading 9-16 bit wide regs */ 654 649 static inline int axp20x_read_variable_width(struct regmap *regmap, 655 650 unsigned int reg, unsigned int width)
+4
include/linux/mfd/cros_ec.h
··· 322 322 extern struct attribute_group cros_ec_lightbar_attr_group; 323 323 extern struct attribute_group cros_ec_vbc_attr_group; 324 324 325 + /* debugfs stuff */ 326 + int cros_ec_debugfs_init(struct cros_ec_dev *ec); 327 + void cros_ec_debugfs_remove(struct cros_ec_dev *ec); 328 + 325 329 /* ACPI GPE handler */ 326 330 #ifdef CONFIG_ACPI 327 331
+17
include/linux/mfd/cros_ec_commands.h
··· 2904 2904 USB_PD_CTRL_MUX_AUTO = 5, 2905 2905 }; 2906 2906 2907 + enum usb_pd_control_swap { 2908 + USB_PD_CTRL_SWAP_NONE = 0, 2909 + USB_PD_CTRL_SWAP_DATA = 1, 2910 + USB_PD_CTRL_SWAP_POWER = 2, 2911 + USB_PD_CTRL_SWAP_VCONN = 3, 2912 + USB_PD_CTRL_SWAP_COUNT 2913 + }; 2914 + 2907 2915 struct ec_params_usb_pd_control { 2908 2916 uint8_t port; 2909 2917 uint8_t role; 2910 2918 uint8_t mux; 2919 + uint8_t swap; 2911 2920 } __packed; 2912 2921 2913 2922 #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ 2914 2923 #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ 2915 2924 #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ 2925 + 2926 + #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ 2927 + #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ 2928 + #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ 2929 + #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ 2930 + #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ 2931 + #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ 2932 + #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */ 2916 2933 2917 2934 struct ec_response_usb_pd_control_v1 { 2918 2935 uint8_t enabled;
+60
include/linux/mfd/rave-sp.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + 3 + /* 4 + * Core definitions for RAVE SP MFD driver. 5 + * 6 + * Copyright (C) 2017 Zodiac Inflight Innovations 7 + */ 8 + 9 + #ifndef _LINUX_RAVE_SP_H_ 10 + #define _LINUX_RAVE_SP_H_ 11 + 12 + #include <linux/notifier.h> 13 + 14 + enum rave_sp_command { 15 + RAVE_SP_CMD_GET_FIRMWARE_VERSION = 0x20, 16 + RAVE_SP_CMD_GET_BOOTLOADER_VERSION = 0x21, 17 + RAVE_SP_CMD_BOOT_SOURCE = 0x26, 18 + RAVE_SP_CMD_GET_BOARD_COPPER_REV = 0x2B, 19 + RAVE_SP_CMD_GET_GPIO_STATE = 0x2F, 20 + 21 + RAVE_SP_CMD_STATUS = 0xA0, 22 + RAVE_SP_CMD_SW_WDT = 0xA1, 23 + RAVE_SP_CMD_PET_WDT = 0xA2, 24 + RAVE_SP_CMD_RESET = 0xA7, 25 + RAVE_SP_CMD_RESET_REASON = 0xA8, 26 + 27 + RAVE_SP_CMD_REQ_COPPER_REV = 0xB6, 28 + RAVE_SP_CMD_GET_I2C_DEVICE_STATUS = 0xBA, 29 + RAVE_SP_CMD_GET_SP_SILICON_REV = 0xB9, 30 + RAVE_SP_CMD_CONTROL_EVENTS = 0xBB, 31 + 32 + RAVE_SP_EVNT_BASE = 0xE0, 33 + }; 34 + 35 + struct rave_sp; 36 + 37 + static inline unsigned long rave_sp_action_pack(u8 event, u8 value) 38 + { 39 + return ((unsigned long)value << 8) | event; 40 + } 41 + 42 + static inline u8 rave_sp_action_unpack_event(unsigned long action) 43 + { 44 + return action; 45 + } 46 + 47 + static inline u8 rave_sp_action_unpack_value(unsigned long action) 48 + { 49 + return action >> 8; 50 + } 51 + 52 + int rave_sp_exec(struct rave_sp *sp, 53 + void *__data, size_t data_size, 54 + void *reply_data, size_t reply_data_size); 55 + 56 + struct device; 57 + int devm_rave_sp_register_event_notifier(struct device *dev, 58 + struct notifier_block *nb); 59 + 60 + #endif /* _LINUX_RAVE_SP_H_ */
include/linux/mfd/rtsx_common.h include/linux/rtsx_common.h
+231 -5
include/linux/mfd/rtsx_pci.h include/linux/rtsx_pci.h
··· 24 24 25 25 #include <linux/sched.h> 26 26 #include <linux/pci.h> 27 - #include <linux/mfd/rtsx_common.h> 27 + #include <linux/rtsx_common.h> 28 28 29 29 #define MAX_RW_REG_CNT 1024 30 30 ··· 203 203 #define SD_DDR_MODE 0x04 204 204 #define SD_30_MODE 0x08 205 205 #define SD_CLK_DIVIDE_MASK 0xC0 206 + #define SD_MODE_SELECT_MASK 0x0C 206 207 #define SD_CFG2 0xFDA1 207 208 #define SD_CALCULATE_CRC7 0x00 208 209 #define SD_NO_CALCULATE_CRC7 0x80 ··· 227 226 #define SD_RSP_TYPE_R6 0x01 228 227 #define SD_RSP_TYPE_R7 0x01 229 228 #define SD_CFG3 0xFDA2 229 + #define SD30_CLK_END_EN 0x10 230 230 #define SD_RSP_80CLK_TIMEOUT_EN 0x01 231 231 232 232 #define SD_STAT1 0xFDA3 ··· 311 309 312 310 #define SD_DATA_STATE 0xFDB6 313 311 #define SD_DATA_IDLE 0x80 312 + #define REG_SD_STOP_SDCLK_CFG 0xFDB8 313 + #define SD30_CLK_STOP_CFG_EN 0x04 314 + #define SD30_CLK_STOP_CFG1 0x02 315 + #define SD30_CLK_STOP_CFG0 0x01 316 + #define REG_PRE_RW_MODE 0xFD70 317 + #define EN_INFINITE_MODE 0x01 314 318 315 319 #define SRCTL 0xFC13 316 320 ··· 442 434 #define CARD_CLK_EN 0xFD69 443 435 #define SD_CLK_EN 0x04 444 436 #define MS_CLK_EN 0x08 437 + #define SD40_CLK_EN 0x10 445 438 #define SDIO_CTRL 0xFD6B 446 439 #define CD_PAD_CTL 0xFD73 447 440 #define CD_DISABLE_MASK 0x07 ··· 462 453 #define FPDCTL 0xFC00 463 454 #define SSC_POWER_DOWN 0x01 464 455 #define SD_OC_POWER_DOWN 0x02 465 - #define ALL_POWER_DOWN 0x07 466 - #define OC_POWER_DOWN 0x06 456 + #define ALL_POWER_DOWN 0x03 457 + #define OC_POWER_DOWN 0x02 467 458 #define PDINFO 0xFC01 468 459 469 460 #define CLK_CTL 0xFC02 ··· 499 490 500 491 #define FPGA_PULL_CTL 0xFC1D 501 492 #define OLT_LED_CTL 0xFC1E 493 + #define LED_SHINE_MASK 0x08 494 + #define LED_SHINE_EN 0x08 495 + #define LED_SHINE_DISABLE 0x00 502 496 #define GPIO_CTL 0xFC1F 503 497 504 498 #define LDO_CTL 0xFC1E ··· 523 511 #define BPP_LDO_ON 0x00 524 512 #define BPP_LDO_SUSPEND 0x02 525 513 #define BPP_LDO_OFF 0x03 514 + #define EFUSE_CTL 0xFC30 515 + #define EFUSE_ADD 0xFC31 526 516 #define SYS_VER 0xFC32 517 + #define EFUSE_DATAL 0xFC34 518 + #define EFUSE_DATAH 0xFC35 527 519 528 520 #define CARD_PULL_CTL1 0xFD60 529 521 #define CARD_PULL_CTL2 0xFD61 ··· 569 553 #define RBBC1 0xFE2F 570 554 #define RBDAT 0xFE30 571 555 #define RBCTL 0xFE34 556 + #define U_AUTO_DMA_EN_MASK 0x20 557 + #define U_AUTO_DMA_DISABLE 0x00 558 + #define RB_FLUSH 0x80 572 559 #define CFGADDR0 0xFE35 573 560 #define CFGADDR1 0xFE36 574 561 #define CFGDATA0 0xFE37 ··· 600 581 #define LTR_LATENCY_MODE_HW 0 601 582 #define LTR_LATENCY_MODE_SW BIT(6) 602 583 #define OBFF_CFG 0xFE4C 584 + #define OBFF_EN_MASK 0x03 585 + #define OBFF_DISABLE 0x00 603 586 604 587 #define CDRESUMECTL 0xFE52 605 588 #define WAKE_SEL_CTL 0xFE54 ··· 616 595 #define FORCE_ASPM_L0_EN 0x01 617 596 #define FORCE_ASPM_NO_ASPM 0x00 618 597 #define PM_CLK_FORCE_CTL 0xFE58 598 + #define CLK_PM_EN 0x01 619 599 #define FUNC_FORCE_CTL 0xFE59 620 600 #define FUNC_FORCE_UPME_XMT_DBG 0x02 621 601 #define PERST_GLITCH_WIDTH 0xFE5C ··· 642 620 #define LDO_PWR_SEL 0xFE78 643 621 644 622 #define L1SUB_CONFIG1 0xFE8D 623 + #define AUX_CLK_ACTIVE_SEL_MASK 0x01 624 + #define MAC_CKSW_DONE 0x00 645 625 #define L1SUB_CONFIG2 0xFE8E 646 626 #define L1SUB_AUTO_CFG 0x02 647 627 #define L1SUB_CONFIG3 0xFE8F 648 628 #define L1OFF_MBIAS2_EN_5250 BIT(7) 649 629 650 630 #define DUMMY_REG_RESET_0 0xFE90 631 + #define IC_VERSION_MASK 0x0F 651 632 633 + #define REG_VREF 0xFE97 634 + #define PWD_SUSPND_EN 0x10 635 + #define RTS5260_DMA_RST_CTL_0 0xFEBF 636 + #define RTS5260_DMA_RST 0x80 637 + #define RTS5260_ADMA3_RST 0x40 652 638 #define AUTOLOAD_CFG_BASE 0xFF00 639 + #define RELINK_TIME_MASK 0x01 653 640 #define PETXCFG 0xFF03 654 641 #define FORCE_CLKREQ_DELINK_MASK BIT(7) 655 642 #define FORCE_CLKREQ_LOW 0x80 ··· 698 667 #define LDO_DV18_CFG 0xFF70 699 668 #define LDO_DV18_SR_MASK 0xC0 700 669 #define LDO_DV18_SR_DF 0x40 670 + #define DV331812_MASK 0x70 671 + #define DV331812_33 0x70 672 + #define DV331812_17 0x30 701 673 702 674 #define LDO_CONFIG2 0xFF71 703 675 #define LDO_D3318_MASK 0x07 704 676 #define LDO_D3318_33V 0x07 705 677 #define LDO_D3318_18V 0x02 678 + #define DV331812_VDD1 0x04 679 + #define DV331812_POWERON 0x08 680 + #define DV331812_POWEROFF 0x00 706 681 707 682 #define LDO_VCC_CFG0 0xFF72 708 683 #define LDO_VCC_LMTVTH_MASK 0x30 709 684 #define LDO_VCC_LMTVTH_2A 0x10 685 + /*RTS5260*/ 686 + #define RTS5260_DVCC_TUNE_MASK 0x70 687 + #define RTS5260_DVCC_33 0x70 710 688 711 689 #define LDO_VCC_CFG1 0xFF73 712 690 #define LDO_VCC_REF_TUNE_MASK 0x30 ··· 724 684 #define LDO_VCC_1V8 0x04 725 685 #define LDO_VCC_3V3 0x07 726 686 #define LDO_VCC_LMT_EN 0x08 687 + /*RTS5260*/ 688 + #define LDO_POW_SDVDD1_MASK 0x08 689 + #define LDO_POW_SDVDD1_ON 0x08 690 + #define LDO_POW_SDVDD1_OFF 0x00 727 691 728 692 #define LDO_VIO_CFG 0xFF75 729 693 #define LDO_VIO_SR_MASK 0xC0 ··· 754 710 #define SD40_VIO_TUNE_1V7 0x30 755 711 #define SD_VIO_LDO_1V8 0x40 756 712 #define SD_VIO_LDO_3V3 0x70 713 + 714 + #define RTS5260_AUTOLOAD_CFG4 0xFF7F 715 + #define RTS5260_MIMO_DISABLE 0x8A 716 + 717 + #define RTS5260_REG_GPIO_CTL0 0xFC1A 718 + #define RTS5260_REG_GPIO_MASK 0x01 719 + #define RTS5260_REG_GPIO_ON 0x01 720 + #define RTS5260_REG_GPIO_OFF 0x00 721 + 722 + #define PWR_GLOBAL_CTRL 0xF200 723 + #define PCIE_L1_2_EN 0x0C 724 + #define PCIE_L1_1_EN 0x0A 725 + #define PCIE_L1_0_EN 0x09 726 + #define PWR_FE_CTL 0xF201 727 + #define PCIE_L1_2_PD_FE_EN 0x0C 728 + #define PCIE_L1_1_PD_FE_EN 0x0A 729 + #define PCIE_L1_0_PD_FE_EN 0x09 730 + #define CFG_PCIE_APHY_OFF_0 0xF204 731 + #define CFG_PCIE_APHY_OFF_0_DEFAULT 0xBF 732 + #define CFG_PCIE_APHY_OFF_1 0xF205 733 + #define CFG_PCIE_APHY_OFF_1_DEFAULT 0xFF 734 + #define CFG_PCIE_APHY_OFF_2 0xF206 735 + #define CFG_PCIE_APHY_OFF_2_DEFAULT 0x01 736 + #define CFG_PCIE_APHY_OFF_3 0xF207 737 + #define CFG_PCIE_APHY_OFF_3_DEFAULT 0x00 738 + #define CFG_L1_0_PCIE_MAC_RET_VALUE 0xF20C 739 + #define CFG_L1_0_PCIE_DPHY_RET_VALUE 0xF20E 740 + #define CFG_L1_0_SYS_RET_VALUE 0xF210 741 + #define CFG_L1_0_CRC_MISC_RET_VALUE 0xF212 742 + #define CFG_L1_0_CRC_SD30_RET_VALUE 0xF214 743 + #define CFG_L1_0_CRC_SD40_RET_VALUE 0xF216 744 + #define CFG_LP_FPWM_VALUE 0xF219 745 + #define CFG_LP_FPWM_VALUE_DEFAULT 0x18 746 + #define PWC_CDR 0xF253 747 + #define PWC_CDR_DEFAULT 0x03 748 + #define CFG_L1_0_RET_VALUE_DEFAULT 0x1B 749 + #define CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT 0x0C 750 + 751 + /* OCPCTL */ 752 + #define SD_DETECT_EN 0x08 753 + #define SD_OCP_INT_EN 0x04 754 + #define SD_OCP_INT_CLR 0x02 755 + #define SD_OC_CLR 0x01 756 + 757 + #define SDVIO_DETECT_EN (1 << 7) 758 + #define SDVIO_OCP_INT_EN (1 << 6) 759 + #define SDVIO_OCP_INT_CLR (1 << 5) 760 + #define SDVIO_OC_CLR (1 << 4) 761 + 762 + /* OCPSTAT */ 763 + #define SD_OCP_DETECT 0x08 764 + #define SD_OC_NOW 0x04 765 + #define SD_OC_EVER 0x02 766 + 767 + #define SDVIO_OC_NOW (1 << 6) 768 + #define SDVIO_OC_EVER (1 << 5) 769 + 770 + #define REG_OCPCTL 0xFD6A 771 + #define REG_OCPSTAT 0xFD6E 772 + #define REG_OCPGLITCH 0xFD6C 773 + #define REG_OCPPARA1 0xFD6B 774 + #define REG_OCPPARA2 0xFD6D 775 + 776 + /* rts5260 DV3318 OCP-related registers */ 777 + #define REG_DV3318_OCPCTL 0xFD89 778 + #define DV3318_OCP_TIME_MASK 0xF0 779 + #define DV3318_DETECT_EN 0x08 780 + #define DV3318_OCP_INT_EN 0x04 781 + #define DV3318_OCP_INT_CLR 0x02 782 + #define DV3318_OCP_CLR 0x01 783 + 784 + #define REG_DV3318_OCPSTAT 0xFD8A 785 + #define DV3318_OCP_GlITCH_TIME_MASK 0xF0 786 + #define DV3318_OCP_DETECT 0x08 787 + #define DV3318_OCP_NOW 0x04 788 + #define DV3318_OCP_EVER 0x02 789 + 790 + #define SD_OCP_GLITCH_MASK 0x0F 791 + 792 + /* OCPPARA1 */ 793 + #define SDVIO_OCP_TIME_60 0x00 794 + #define SDVIO_OCP_TIME_100 0x10 795 + #define SDVIO_OCP_TIME_200 0x20 796 + #define SDVIO_OCP_TIME_400 0x30 797 + #define SDVIO_OCP_TIME_600 0x40 798 + #define SDVIO_OCP_TIME_800 0x50 799 + #define SDVIO_OCP_TIME_1100 0x60 800 + #define SDVIO_OCP_TIME_MASK 0x70 801 + 802 + #define SD_OCP_TIME_60 0x00 803 + #define SD_OCP_TIME_100 0x01 804 + #define SD_OCP_TIME_200 0x02 805 + #define SD_OCP_TIME_400 0x03 806 + #define SD_OCP_TIME_600 0x04 807 + #define SD_OCP_TIME_800 0x05 808 + #define SD_OCP_TIME_1100 0x06 809 + #define SD_OCP_TIME_MASK 0x07 810 + 811 + /* OCPPARA2 */ 812 + #define SDVIO_OCP_THD_190 0x00 813 + #define SDVIO_OCP_THD_250 0x10 814 + #define SDVIO_OCP_THD_320 0x20 815 + #define SDVIO_OCP_THD_380 0x30 816 + #define SDVIO_OCP_THD_440 0x40 817 + #define SDVIO_OCP_THD_500 0x50 818 + #define SDVIO_OCP_THD_570 0x60 819 + #define SDVIO_OCP_THD_630 0x70 820 + #define SDVIO_OCP_THD_MASK 0x70 821 + 822 + #define SD_OCP_THD_450 0x00 823 + #define SD_OCP_THD_550 0x01 824 + #define SD_OCP_THD_650 0x02 825 + #define SD_OCP_THD_750 0x03 826 + #define SD_OCP_THD_850 0x04 827 + #define SD_OCP_THD_950 0x05 828 + #define SD_OCP_THD_1050 0x06 829 + #define SD_OCP_THD_1150 0x07 830 + #define SD_OCP_THD_MASK 0x07 831 + 832 + #define SDVIO_OCP_GLITCH_MASK 0xF0 833 + #define SDVIO_OCP_GLITCH_NONE 0x00 834 + #define SDVIO_OCP_GLITCH_50U 0x10 835 + #define SDVIO_OCP_GLITCH_100U 0x20 836 + #define SDVIO_OCP_GLITCH_200U 0x30 837 + #define SDVIO_OCP_GLITCH_600U 0x40 838 + #define SDVIO_OCP_GLITCH_800U 0x50 839 + #define SDVIO_OCP_GLITCH_1M 0x60 840 + #define SDVIO_OCP_GLITCH_2M 0x70 841 + #define SDVIO_OCP_GLITCH_3M 0x80 842 + #define SDVIO_OCP_GLITCH_4M 0x90 843 + #define SDVIO_OCP_GLIVCH_5M 0xA0 844 + #define SDVIO_OCP_GLITCH_6M 0xB0 845 + #define SDVIO_OCP_GLITCH_7M 0xC0 846 + #define SDVIO_OCP_GLITCH_8M 0xD0 847 + #define SDVIO_OCP_GLITCH_9M 0xE0 848 + #define SDVIO_OCP_GLITCH_10M 0xF0 849 + 850 + #define SD_OCP_GLITCH_MASK 0x0F 851 + #define SD_OCP_GLITCH_NONE 0x00 852 + #define SD_OCP_GLITCH_50U 0x01 853 + #define SD_OCP_GLITCH_100U 0x02 854 + #define SD_OCP_GLITCH_200U 0x03 855 + #define SD_OCP_GLITCH_600U 0x04 856 + #define SD_OCP_GLITCH_800U 0x05 857 + #define SD_OCP_GLITCH_1M 0x06 858 + #define SD_OCP_GLITCH_2M 0x07 859 + #define SD_OCP_GLITCH_3M 0x08 860 + #define SD_OCP_GLITCH_4M 0x09 861 + #define SD_OCP_GLIVCH_5M 0x0A 862 + #define SD_OCP_GLITCH_6M 0x0B 863 + #define SD_OCP_GLITCH_7M 0x0C 864 + #define SD_OCP_GLITCH_8M 0x0D 865 + #define SD_OCP_GLITCH_9M 0x0E 866 + #define SD_OCP_GLITCH_10M 0x0F 757 867 758 868 /* Phy register */ 759 869 #define PHY_PCR 0x00 ··· 1055 857 1056 858 #define PCR_ASPM_SETTING_REG1 0x160 1057 859 #define PCR_ASPM_SETTING_REG2 0x168 860 + #define PCR_ASPM_SETTING_5260 0x178 1058 861 1059 862 #define PCR_SETTING_REG1 0x724 1060 863 #define PCR_SETTING_REG2 0x814 ··· 1089 890 int (*conv_clk_and_div_n)(int clk, int dir); 1090 891 void (*fetch_vendor_settings)(struct rtsx_pcr *pcr); 1091 892 void (*force_power_down)(struct rtsx_pcr *pcr, u8 pm_state); 893 + void (*stop_cmd)(struct rtsx_pcr *pcr); 1092 894 1093 895 void (*set_aspm)(struct rtsx_pcr *pcr, bool enable); 1094 896 int (*set_ltr_latency)(struct rtsx_pcr *pcr, u32 latency); ··· 1097 897 void (*set_l1off_cfg_sub_d0)(struct rtsx_pcr *pcr, int active); 1098 898 void (*full_on)(struct rtsx_pcr *pcr); 1099 899 void (*power_saving)(struct rtsx_pcr *pcr); 900 + void (*enable_ocp)(struct rtsx_pcr *pcr); 901 + void (*disable_ocp)(struct rtsx_pcr *pcr); 902 + void (*init_ocp)(struct rtsx_pcr *pcr); 903 + void (*process_ocp)(struct rtsx_pcr *pcr); 904 + int (*get_ocpstat)(struct rtsx_pcr *pcr, u8 *val); 905 + void (*clear_ocpstat)(struct rtsx_pcr *pcr); 1100 906 }; 1101 907 1102 908 enum PDEV_STAT {PDEV_STAT_IDLE, PDEV_STAT_RUN}; ··· 1141 935 * @l1_snooze_delay: l1 snooze delay 1142 936 * @ltr_l1off_sspwrgate: ltr l1off sspwrgate 1143 937 * @ltr_l1off_snooze_sspwrgate: ltr l1off snooze sspwrgate 938 + * @ocp_en: enable ocp flag 939 + * @sd_400mA_ocp_thd: 400mA ocp thd 940 + * @sd_800mA_ocp_thd: 800mA ocp thd 1144 941 */ 1145 942 struct rtsx_cr_option { 1146 943 u32 dev_flags; ··· 1158 949 u32 l1_snooze_delay; 1159 950 u8 ltr_l1off_sspwrgate; 1160 951 u8 ltr_l1off_snooze_sspwrgate; 952 + bool ocp_en; 953 + u8 sd_400mA_ocp_thd; 954 + u8 sd_800mA_ocp_thd; 955 + }; 956 + 957 + /* 958 + * struct rtsx_hw_param - card reader hardware param 959 + * @interrupt_en: indicate which interrutp enable 960 + * @ocp_glitch: ocp glitch time 961 + */ 962 + struct rtsx_hw_param { 963 + u32 interrupt_en; 964 + u8 ocp_glitch; 1161 965 }; 1162 966 1163 967 #define rtsx_set_dev_flag(cr, flag) \ ··· 1185 963 unsigned int id; 1186 964 int pcie_cap; 1187 965 struct rtsx_cr_option option; 966 + struct rtsx_hw_param hw_param; 1188 967 1189 968 /* pci resources */ 1190 969 unsigned long addr; ··· 1265 1042 struct rtsx_slot *slots; 1266 1043 1267 1044 u8 dma_error_count; 1045 + u8 ocp_stat; 1046 + u8 ocp_stat2; 1268 1047 }; 1269 1048 1270 1049 #define PID_524A 0x524A 1271 - #define PID_5249 0x5249 1272 - #define PID_5250 0x5250 1050 + #define PID_5249 0x5249 1051 + #define PID_5250 0x5250 1273 1052 #define PID_525A 0x525A 1053 + #define PID_5260 0x5260 1274 1054 1275 1055 #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid)) 1276 1056 #define PCI_VID(pcr) ((pcr)->pci->vendor)
include/linux/mfd/rtsx_usb.h include/linux/rtsx_usb.h
+1
include/linux/serdev.h
··· 193 193 194 194 int serdev_device_open(struct serdev_device *); 195 195 void serdev_device_close(struct serdev_device *); 196 + int devm_serdev_device_open(struct device *, struct serdev_device *); 196 197 unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int); 197 198 void serdev_device_set_flow_control(struct serdev_device *, bool); 198 199 int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t);
+57 -1
lib/crc-ccitt.c
··· 51 51 }; 52 52 EXPORT_SYMBOL(crc_ccitt_table); 53 53 54 + /* 55 + * Similar table to calculate CRC16 variant known as CRC-CCITT-FALSE 56 + * Reflected bits order, does not augment final value. 57 + */ 58 + u16 const crc_ccitt_false_table[256] = { 59 + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 60 + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 61 + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 62 + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 63 + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 64 + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 65 + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 66 + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 67 + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 68 + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, 69 + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 70 + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, 71 + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 72 + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 73 + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 74 + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 75 + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 76 + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, 77 + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 78 + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, 79 + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 80 + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 81 + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 82 + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, 83 + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 84 + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, 85 + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 86 + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 87 + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 88 + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 89 + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 90 + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 91 + }; 92 + EXPORT_SYMBOL(crc_ccitt_false_table); 93 + 54 94 /** 55 - * crc_ccitt - recompute the CRC for the data buffer 95 + * crc_ccitt - recompute the CRC (CRC-CCITT variant) for the data 96 + * buffer 56 97 * @crc: previous CRC value 57 98 * @buffer: data pointer 58 99 * @len: number of bytes in the buffer ··· 105 64 return crc; 106 65 } 107 66 EXPORT_SYMBOL(crc_ccitt); 67 + 68 + /** 69 + * crc_ccitt_false - recompute the CRC (CRC-CCITT-FALSE variant) 70 + * for the data buffer 71 + * @crc: previous CRC value 72 + * @buffer: data pointer 73 + * @len: number of bytes in the buffer 74 + */ 75 + u16 crc_ccitt_false(u16 crc, u8 const *buffer, size_t len) 76 + { 77 + while (len--) 78 + crc = crc_ccitt_false_byte(crc, *buffer++); 79 + return crc; 80 + } 81 + EXPORT_SYMBOL(crc_ccitt_false); 108 82 109 83 MODULE_DESCRIPTION("CRC-CCITT calculations"); 110 84 MODULE_LICENSE("GPL");