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

Merge tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc

Pull char/misc driver updates from Greg KH:
"Here is the big set of new char/misc driver drivers and features for
4.12-rc1.

There's lots of new drivers added this time around, new firmware
drivers from Google, more auxdisplay drivers, extcon drivers, fpga
drivers, and a bunch of other driver updates. Nothing major, except if
you happen to have the hardware for these drivers, and then you will
be happy :)

All of these have been in linux-next for a while with no reported
issues"

* tag 'char-misc-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (136 commits)
firmware: google memconsole: Fix return value check in platform_memconsole_init()
firmware: Google VPD: Fix return value check in vpd_platform_init()
goldfish_pipe: fix build warning about using too much stack.
goldfish_pipe: An implementation of more parallel pipe
fpga fr br: update supported version numbers
fpga: region: release FPGA region reference in error path
fpga altera-hps2fpga: disable/unprepare clock on error in alt_fpga_bridge_probe()
mei: drop the TODO from samples
firmware: Google VPD sysfs driver
firmware: Google VPD: import lib_vpd source files
misc: lkdtm: Add volatile to intentional NULL pointer reference
eeprom: idt_89hpesx: Add OF device ID table
misc: ds1682: Add OF device ID table
misc: tsl2550: Add OF device ID table
w1: Remove unneeded use of assert() and remove w1_log.h
w1: Use kernel common min() implementation
uio_mf624: Align memory regions to page size and set correct offsets
uio_mf624: Refactor memory info initialization
uio: Allow handling of non page-aligned memory regions
hangcheck-timer: Fix typo in comment
...

+8092 -3287
-3
Documentation/DocBook/rapidio.tmpl
··· 129 129 <sect1 id="Device_model_support"><title>Device model support</title> 130 130 !Idrivers/rapidio/rio-driver.c 131 131 </sect1> 132 - <sect1 id="Sysfs_support"><title>Sysfs support</title> 133 - !Idrivers/rapidio/rio-sysfs.c 134 - </sect1> 135 132 <sect1 id="PPC32_support"><title>PPC32 support</title> 136 133 !Iarch/powerpc/sysdev/fsl_rio.c 137 134 </sect1>
+45
Documentation/devicetree/bindings/auxdisplay/hit,hd44780.txt
··· 1 + DT bindings for the Hitachi HD44780 Character LCD Controller 2 + 3 + The Hitachi HD44780 Character LCD Controller is commonly used on character LCDs 4 + that can display one or more lines of text. It exposes an M6800 bus interface, 5 + which can be used in either 4-bit or 8-bit mode. 6 + 7 + Required properties: 8 + - compatible: Must contain "hit,hd44780", 9 + - data-gpios: Must contain an array of either 4 or 8 GPIO specifiers, 10 + referring to the GPIO pins connected to the data signal lines DB0-DB7 11 + (8-bit mode) or DB4-DB7 (4-bit mode) of the LCD Controller's bus interface, 12 + - enable-gpios: Must contain a GPIO specifier, referring to the GPIO pin 13 + connected to the "E" (Enable) signal line of the LCD Controller's bus 14 + interface, 15 + - rs-gpios: Must contain a GPIO specifier, referring to the GPIO pin 16 + connected to the "RS" (Register Select) signal line of the LCD Controller's 17 + bus interface, 18 + - display-height-chars: Height of the display, in character cells, 19 + - display-width-chars: Width of the display, in character cells. 20 + 21 + Optional properties: 22 + - rw-gpios: Must contain a GPIO specifier, referring to the GPIO pin 23 + connected to the "RW" (Read/Write) signal line of the LCD Controller's bus 24 + interface, 25 + - backlight-gpios: Must contain a GPIO specifier, referring to the GPIO pin 26 + used for enabling the LCD's backlight, 27 + - internal-buffer-width: Internal buffer width (default is 40 for displays 28 + with 1 or 2 lines, and display-width-chars for displays with more than 2 29 + lines). 30 + 31 + Example: 32 + 33 + auxdisplay { 34 + compatible = "hit,hd44780"; 35 + 36 + data-gpios = <&hc595 0 GPIO_ACTIVE_HIGH>, 37 + <&hc595 1 GPIO_ACTIVE_HIGH>, 38 + <&hc595 2 GPIO_ACTIVE_HIGH>, 39 + <&hc595 3 GPIO_ACTIVE_HIGH>; 40 + enable-gpios = <&hc595 4 GPIO_ACTIVE_HIGH>; 41 + rs-gpios = <&hc595 5 GPIO_ACTIVE_HIGH>; 42 + 43 + display-height-chars = <2>; 44 + display-width-chars = <16>; 45 + };
+33
Documentation/devicetree/bindings/firmware/coreboot.txt
··· 1 + COREBOOT firmware information 2 + 3 + The device tree node to communicate the location of coreboot's memory-resident 4 + bookkeeping structures to the kernel. Since coreboot itself cannot boot a 5 + device-tree-based kernel (yet), this node needs to be inserted by a 6 + second-stage bootloader (a coreboot "payload"). 7 + 8 + Required properties: 9 + - compatible: Should be "coreboot" 10 + - reg: Address and length of the following two memory regions, in order: 11 + 1.) The coreboot table. This is a list of variable-sized descriptors 12 + that contain various compile- and run-time generated firmware 13 + parameters. It is identified by the magic string "LBIO" in its first 14 + four bytes. 15 + See coreboot's src/commonlib/include/commonlib/coreboot_tables.h for 16 + details. 17 + 2.) The CBMEM area. This is a downward-growing memory region used by 18 + coreboot to dynamically allocate data structures that remain resident. 19 + It may or may not include the coreboot table as one of its members. It 20 + is identified by a root node descriptor with the magic number 21 + 0xc0389481 that resides in the topmost 8 bytes of the area. 22 + See coreboot's src/include/imd.h for details. 23 + 24 + Example: 25 + firmware { 26 + ranges; 27 + 28 + coreboot { 29 + compatible = "coreboot"; 30 + reg = <0xfdfea000 0x264>, 31 + <0xfdfea000 0x16000>; 32 + } 33 + };
+12
Documentation/devicetree/bindings/fpga/altera-pr-ip.txt
··· 1 + Altera Arria10 Partial Reconfiguration IP 2 + 3 + Required properties: 4 + - compatible : should contain "altr,a10-pr-ip" 5 + - reg : base address and size for memory mapped io. 6 + 7 + Example: 8 + 9 + fpga_mgr: fpga-mgr@ff20c000 { 10 + compatible = "altr,a10-pr-ip"; 11 + reg = <0xff20c000 0x10>; 12 + };
+1
Documentation/devicetree/bindings/fpga/fpga-region.txt
··· 186 186 otherwise full reconfiguration is done. 187 187 - external-fpga-config : boolean, set if the FPGA has already been configured 188 188 prior to OS boot up. 189 + - encrypted-fpga-config : boolean, set if the bitstream is encrypted 189 190 - region-unfreeze-timeout-us : The maximum time in microseconds to wait for 190 191 bridges to successfully become enabled after the region has been 191 192 programmed.
+21
Documentation/devicetree/bindings/fpga/lattice-ice40-fpga-mgr.txt
··· 1 + Lattice iCE40 FPGA Manager 2 + 3 + Required properties: 4 + - compatible: Should contain "lattice,ice40-fpga-mgr" 5 + - reg: SPI chip select 6 + - spi-max-frequency: Maximum SPI frequency (>=1000000, <=25000000) 7 + - cdone-gpios: GPIO input connected to CDONE pin 8 + - reset-gpios: Active-low GPIO output connected to CRESET_B pin. Note 9 + that unless the GPIO is held low during startup, the 10 + FPGA will enter Master SPI mode and drive SCK with a 11 + clock signal potentially jamming other devices on the 12 + bus until the firmware is loaded. 13 + 14 + Example: 15 + fpga: fpga@0 { 16 + compatible = "lattice,ice40-fpga-mgr"; 17 + reg = <0>; 18 + spi-max-frequency = <1000000>; 19 + cdone-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>; 20 + reset-gpios = <&gpio 22 GPIO_ACTIVE_LOW>; 21 + };
+44
Documentation/devicetree/bindings/fpga/xilinx-slave-serial.txt
··· 1 + Xilinx Slave Serial SPI FPGA Manager 2 + 3 + Xilinx Spartan-6 FPGAs support a method of loading the bitstream over 4 + what is referred to as "slave serial" interface. 5 + The slave serial link is not technically SPI, and might require extra 6 + circuits in order to play nicely with other SPI slaves on the same bus. 7 + 8 + See https://www.xilinx.com/support/documentation/user_guides/ug380.pdf 9 + 10 + Required properties: 11 + - compatible: should contain "xlnx,fpga-slave-serial" 12 + - reg: spi chip select of the FPGA 13 + - prog_b-gpios: config pin (referred to as PROGRAM_B in the manual) 14 + - done-gpios: config status pin (referred to as DONE in the manual) 15 + 16 + Example for full FPGA configuration: 17 + 18 + fpga-region0 { 19 + compatible = "fpga-region"; 20 + fpga-mgr = <&fpga_mgr_spi>; 21 + #address-cells = <0x1>; 22 + #size-cells = <0x1>; 23 + }; 24 + 25 + spi1: spi@10680 { 26 + compatible = "marvell,armada-xp-spi", "marvell,orion-spi"; 27 + pinctrl-0 = <&spi0_pins>; 28 + pinctrl-names = "default"; 29 + #address-cells = <1>; 30 + #size-cells = <0>; 31 + cell-index = <1>; 32 + interrupts = <92>; 33 + clocks = <&coreclk 0>; 34 + status = "okay"; 35 + 36 + fpga_mgr_spi: fpga-mgr@0 { 37 + compatible = "xlnx,fpga-slave-serial"; 38 + spi-max-frequency = <60000000>; 39 + spi-cpha; 40 + reg = <0>; 41 + done-gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; 42 + prog_b-gpios = <&gpio0 29 GPIO_ACTIVE_LOW>; 43 + }; 44 + };
+5 -1
Documentation/devicetree/bindings/nvmem/allwinner,sunxi-sid.txt
··· 1 1 Allwinner sunxi-sid 2 2 3 3 Required properties: 4 - - compatible: "allwinner,sun4i-a10-sid" or "allwinner,sun7i-a20-sid" 4 + - compatible: Should be one of the following: 5 + "allwinner,sun4i-a10-sid" 6 + "allwinner,sun7i-a20-sid" 7 + "allwinner,sun8i-h3-sid" 8 + 5 9 - reg: Should contain registers location and length 6 10 7 11 = Data cells =
+22
Documentation/devicetree/bindings/nvmem/imx-iim.txt
··· 1 + Freescale i.MX IC Identification Module (IIM) device tree bindings 2 + 3 + This binding represents the IC Identification Module (IIM) found on 4 + i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 and i.MX53 SoCs. 5 + 6 + Required properties: 7 + - compatible: should be one of 8 + "fsl,imx25-iim", "fsl,imx27-iim", 9 + "fsl,imx31-iim", "fsl,imx35-iim", 10 + "fsl,imx51-iim", "fsl,imx53-iim", 11 + - reg: Should contain the register base and length. 12 + - interrupts: Should contain the interrupt for the IIM 13 + - clocks: Should contain a phandle pointing to the gated peripheral clock. 14 + 15 + Example: 16 + 17 + iim: iim@63f98000 { 18 + compatible = "fsl,imx53-iim", "fsl,imx27-iim"; 19 + reg = <0x63f98000 0x4000>; 20 + interrupts = <69>; 21 + clocks = <&clks IMX5_CLK_IIM_GATE>; 22 + };
+5
Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
··· 9 9 "fsl,imx6sl-ocotp" (i.MX6SL), or 10 10 "fsl,imx6sx-ocotp" (i.MX6SX), 11 11 "fsl,imx6ul-ocotp" (i.MX6UL), 12 + "fsl,imx7d-ocotp" (i.MX7D/S), 12 13 followed by "syscon". 13 14 - reg: Should contain the register base and length. 14 15 - clocks: Should contain a phandle pointing to the gated peripheral clock. 16 + 17 + Optional properties: 18 + - read-only: disable write access 15 19 16 20 Example: 17 21 ··· 23 19 compatible = "fsl,imx6q-ocotp", "syscon"; 24 20 reg = <0x021bc000 0x4000>; 25 21 clocks = <&clks IMX6QDL_CLK_IIM>; 22 + read-only; 26 23 };
+93 -270
Documentation/driver-api/vme.rst
··· 6 6 7 7 As with other subsystems within the Linux kernel, VME device drivers register 8 8 with the VME subsystem, typically called from the devices init routine. This is 9 - achieved via a call to the following function: 9 + achieved via a call to :c:func:`vme_register_driver`. 10 10 11 - .. code-block:: c 11 + A pointer to a structure of type :c:type:`struct vme_driver <vme_driver>` must 12 + be provided to the registration function. Along with the maximum number of 13 + devices your driver is able to support. 12 14 13 - int vme_register_driver (struct vme_driver *driver, unsigned int ndevs); 14 - 15 - If driver registration is successful this function returns zero, if an error 16 - occurred a negative error code will be returned. 17 - 18 - A pointer to a structure of type 'vme_driver' must be provided to the 19 - registration function. Along with ndevs, which is the number of devices your 20 - driver is able to support. The structure is as follows: 21 - 22 - .. code-block:: c 23 - 24 - struct vme_driver { 25 - struct list_head node; 26 - const char *name; 27 - int (*match)(struct vme_dev *); 28 - int (*probe)(struct vme_dev *); 29 - int (*remove)(struct vme_dev *); 30 - void (*shutdown)(void); 31 - struct device_driver driver; 32 - struct list_head devices; 33 - unsigned int ndev; 34 - }; 35 - 36 - At the minimum, the '.name', '.match' and '.probe' elements of this structure 37 - should be correctly set. The '.name' element is a pointer to a string holding 38 - the device driver's name. 15 + At the minimum, the '.name', '.match' and '.probe' elements of 16 + :c:type:`struct vme_driver <vme_driver>` should be correctly set. The '.name' 17 + element is a pointer to a string holding the device driver's name. 39 18 40 19 The '.match' function allows control over which VME devices should be registered 41 20 with the driver. The match function should return 1 if a device should be ··· 33 54 } 34 55 35 56 The '.probe' element should contain a pointer to the probe routine. The 36 - probe routine is passed a 'struct vme_dev' pointer as an argument. The 37 - 'struct vme_dev' structure looks like the following: 38 - 39 - .. code-block:: c 40 - 41 - struct vme_dev { 42 - int num; 43 - struct vme_bridge *bridge; 44 - struct device dev; 45 - struct list_head drv_list; 46 - struct list_head bridge_list; 47 - }; 57 + probe routine is passed a :c:type:`struct vme_dev <vme_dev>` pointer as an 58 + argument. 48 59 49 60 Here, the 'num' field refers to the sequential device ID for this specific 50 61 driver. The bridge number (or bus number) can be accessed using 51 62 dev->bridge->num. 52 63 53 - A function is also provided to unregister the driver from the VME core and is 54 - usually called from the device driver's exit routine: 55 - 56 - .. code-block:: c 57 - 58 - void vme_unregister_driver (struct vme_driver *driver); 64 + A function is also provided to unregister the driver from the VME core called 65 + :c:func:`vme_unregister_driver` and should usually be called from the device 66 + driver's exit routine. 59 67 60 68 61 69 Resource management ··· 56 90 device structure. This pointer should be saved, it will be required for 57 91 requesting VME resources. 58 92 59 - The driver can request ownership of one or more master windows, slave windows 60 - and/or dma channels. Rather than allowing the device driver to request a 61 - specific window or DMA channel (which may be used by a different driver) this 62 - driver allows a resource to be assigned based on the required attributes of the 63 - driver in question: 64 - 65 - .. code-block:: c 66 - 67 - struct vme_resource * vme_master_request(struct vme_dev *dev, 68 - u32 aspace, u32 cycle, u32 width); 69 - 70 - struct vme_resource * vme_slave_request(struct vme_dev *dev, u32 aspace, 71 - u32 cycle); 72 - 73 - struct vme_resource *vme_dma_request(struct vme_dev *dev, u32 route); 74 - 75 - For slave windows these attributes are split into the VME address spaces that 76 - need to be accessed in 'aspace' and VME bus cycle types required in 'cycle'. 77 - Master windows add a further set of attributes in 'width' specifying the 78 - required data transfer widths. These attributes are defined as bitmasks and as 79 - such any combination of the attributes can be requested for a single window, 80 - the core will assign a window that meets the requirements, returning a pointer 81 - of type vme_resource that should be used to identify the allocated resource 82 - when it is used. For DMA controllers, the request function requires the 83 - potential direction of any transfers to be provided in the route attributes. 84 - This is typically VME-to-MEM and/or MEM-to-VME, though some hardware can 85 - support VME-to-VME and MEM-to-MEM transfers as well as test pattern generation. 86 - If an unallocated window fitting the requirements can not be found a NULL 87 - pointer will be returned. 93 + The driver can request ownership of one or more master windows 94 + (:c:func:`vme_master_request`), slave windows (:c:func:`vme_slave_request`) 95 + and/or dma channels (:c:func:`vme_dma_request`). Rather than allowing the device 96 + driver to request a specific window or DMA channel (which may be used by a 97 + different driver) the API allows a resource to be assigned based on the required 98 + attributes of the driver in question. For slave windows these attributes are 99 + split into the VME address spaces that need to be accessed in 'aspace' and VME 100 + bus cycle types required in 'cycle'. Master windows add a further set of 101 + attributes in 'width' specifying the required data transfer widths. These 102 + attributes are defined as bitmasks and as such any combination of the 103 + attributes can be requested for a single window, the core will assign a window 104 + that meets the requirements, returning a pointer of type vme_resource that 105 + should be used to identify the allocated resource when it is used. For DMA 106 + controllers, the request function requires the potential direction of any 107 + transfers to be provided in the route attributes. This is typically VME-to-MEM 108 + and/or MEM-to-VME, though some hardware can support VME-to-VME and MEM-to-MEM 109 + transfers as well as test pattern generation. If an unallocated window fitting 110 + the requirements can not be found a NULL pointer will be returned. 88 111 89 112 Functions are also provided to free window allocations once they are no longer 90 - required. These functions should be passed the pointer to the resource provided 91 - during resource allocation: 92 - 93 - .. code-block:: c 94 - 95 - void vme_master_free(struct vme_resource *res); 96 - 97 - void vme_slave_free(struct vme_resource *res); 98 - 99 - void vme_dma_free(struct vme_resource *res); 113 + required. These functions (:c:func:`vme_master_free`, :c:func:`vme_slave_free` 114 + and :c:func:`vme_dma_free`) should be passed the pointer to the resource 115 + provided during resource allocation. 100 116 101 117 102 118 Master windows ··· 92 144 Master window configuration 93 145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 94 146 95 - Once a master window has been assigned the following functions can be used to 96 - configure it and retrieve the current settings: 97 - 98 - .. code-block:: c 99 - 100 - int vme_master_set (struct vme_resource *res, int enabled, 101 - unsigned long long base, unsigned long long size, u32 aspace, 102 - u32 cycle, u32 width); 103 - 104 - int vme_master_get (struct vme_resource *res, int *enabled, 105 - unsigned long long *base, unsigned long long *size, u32 *aspace, 106 - u32 *cycle, u32 *width); 107 - 108 - The address spaces, transfer widths and cycle types are the same as described 147 + Once a master window has been assigned :c:func:`vme_master_set` can be used to 148 + configure it and :c:func:`vme_master_get` to retrieve the current settings. The 149 + address spaces, transfer widths and cycle types are the same as described 109 150 under resource management, however some of the options are mutually exclusive. 110 151 For example, only one address space may be specified. 111 - 112 - These functions return 0 on success or an error code should the call fail. 113 152 114 153 115 154 Master window access 116 155 ~~~~~~~~~~~~~~~~~~~~ 117 156 118 - The following functions can be used to read from and write to configured master 119 - windows. These functions return the number of bytes copied: 157 + The function :c:func:`vme_master_read` can be used to read from and 158 + :c:func:`vme_master_write` used to write to configured master windows. 120 159 121 - .. code-block:: c 122 - 123 - ssize_t vme_master_read(struct vme_resource *res, void *buf, 124 - size_t count, loff_t offset); 125 - 126 - ssize_t vme_master_write(struct vme_resource *res, void *buf, 127 - size_t count, loff_t offset); 128 - 129 - In addition to simple reads and writes, a function is provided to do a 130 - read-modify-write transaction. This function returns the original value of the 131 - VME bus location : 132 - 133 - .. code-block:: c 134 - 135 - unsigned int vme_master_rmw (struct vme_resource *res, 136 - unsigned int mask, unsigned int compare, unsigned int swap, 137 - loff_t offset); 138 - 139 - This functions by reading the offset, applying the mask. If the bits selected in 140 - the mask match with the values of the corresponding bits in the compare field, 141 - the value of swap is written the specified offset. 142 - 143 - Parts of a VME window can be mapped into user space memory using the following 144 - function: 145 - 146 - .. code-block:: c 147 - 148 - int vme_master_mmap(struct vme_resource *resource, 149 - struct vm_area_struct *vma) 160 + In addition to simple reads and writes, :c:func:`vme_master_rmw` is provided to 161 + do a read-modify-write transaction. Parts of a VME window can also be mapped 162 + into user space memory using :c:func:`vme_master_mmap`. 150 163 151 164 152 165 Slave windows ··· 122 213 Slave window configuration 123 214 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 124 215 125 - Once a slave window has been assigned the following functions can be used to 126 - configure it and retrieve the current settings: 127 - 128 - .. code-block:: c 129 - 130 - int vme_slave_set (struct vme_resource *res, int enabled, 131 - unsigned long long base, unsigned long long size, 132 - dma_addr_t mem, u32 aspace, u32 cycle); 133 - 134 - int vme_slave_get (struct vme_resource *res, int *enabled, 135 - unsigned long long *base, unsigned long long *size, 136 - dma_addr_t *mem, u32 *aspace, u32 *cycle); 216 + Once a slave window has been assigned :c:func:`vme_slave_set` can be used to 217 + configure it and :c:func:`vme_slave_get` to retrieve the current settings. 137 218 138 219 The address spaces, transfer widths and cycle types are the same as described 139 220 under resource management, however some of the options are mutually exclusive. 140 221 For example, only one address space may be specified. 141 222 142 - These functions return 0 on success or an error code should the call fail. 143 - 144 223 145 224 Slave window buffer allocation 146 225 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 147 226 148 - Functions are provided to allow the user to allocate and free a contiguous 149 - buffers which will be accessible by the VME bridge. These functions do not have 150 - to be used, other methods can be used to allocate a buffer, though care must be 151 - taken to ensure that they are contiguous and accessible by the VME bridge: 152 - 153 - .. code-block:: c 154 - 155 - void * vme_alloc_consistent(struct vme_resource *res, size_t size, 156 - dma_addr_t *mem); 157 - 158 - void vme_free_consistent(struct vme_resource *res, size_t size, 159 - void *virt, dma_addr_t mem); 227 + Functions are provided to allow the user to allocate 228 + (:c:func:`vme_alloc_consistent`) and free (:c:func:`vme_free_consistent`) 229 + contiguous buffers which will be accessible by the VME bridge. These functions 230 + do not have to be used, other methods can be used to allocate a buffer, though 231 + care must be taken to ensure that they are contiguous and accessible by the VME 232 + bridge. 160 233 161 234 162 235 Slave window access ··· 160 269 List Management 161 270 ~~~~~~~~~~~~~~~ 162 271 163 - The following functions are provided to create and destroy DMA lists. Execution 164 - of a list will not automatically destroy the list, thus enabling a list to be 165 - reused for repetitive tasks: 166 - 167 - .. code-block:: c 168 - 169 - struct vme_dma_list *vme_new_dma_list(struct vme_resource *res); 170 - 171 - int vme_dma_list_free(struct vme_dma_list *list); 272 + The function :c:func:`vme_new_dma_list` is provided to create and 273 + :c:func:`vme_dma_list_free` to destroy DMA lists. Execution of a list will not 274 + automatically destroy the list, thus enabling a list to be reused for repetitive 275 + tasks. 172 276 173 277 174 278 List Population 175 279 ~~~~~~~~~~~~~~~ 176 280 177 - An item can be added to a list using the following function ( the source and 281 + An item can be added to a list using :c:func:`vme_dma_list_add` (the source and 178 282 destination attributes need to be created before calling this function, this is 179 - covered under "Transfer Attributes"): 180 - 181 - .. code-block:: c 182 - 183 - int vme_dma_list_add(struct vme_dma_list *list, 184 - struct vme_dma_attr *src, struct vme_dma_attr *dest, 185 - size_t count); 283 + covered under "Transfer Attributes"). 186 284 187 285 .. note:: 188 286 ··· 190 310 of source and destination. There are functions to create attributes for PCI, VME 191 311 and pattern sources and destinations (where appropriate): 192 312 193 - Pattern source: 313 + - PCI source or destination: :c:func:`vme_dma_pci_attribute` 314 + - VME source or destination: :c:func:`vme_dma_vme_attribute` 315 + - Pattern source: :c:func:`vme_dma_pattern_attribute` 194 316 195 - .. code-block:: c 196 - 197 - struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type); 198 - 199 - PCI source or destination: 200 - 201 - .. code-block:: c 202 - 203 - struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t mem); 204 - 205 - VME source or destination: 206 - 207 - .. code-block:: c 208 - 209 - struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long base, 210 - u32 aspace, u32 cycle, u32 width); 211 - 212 - The following function should be used to free an attribute: 213 - 214 - .. code-block:: c 215 - 216 - void vme_dma_free_attribute(struct vme_dma_attr *attr); 317 + The function :c:func:`vme_dma_free_attribute` should be used to free an 318 + attribute. 217 319 218 320 219 321 List Execution 220 322 ~~~~~~~~~~~~~~ 221 323 222 - The following function queues a list for execution. The function will return 223 - once the list has been executed: 224 - 225 - .. code-block:: c 226 - 227 - int vme_dma_list_exec(struct vme_dma_list *list); 324 + The function :c:func:`vme_dma_list_exec` queues a list for execution and will 325 + return once the list has been executed. 228 326 229 327 230 328 Interrupts ··· 216 358 Attaching Interrupt Handlers 217 359 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 218 360 219 - The following functions can be used to attach and free a specific VME level and 220 - status ID combination. Any given combination can only be assigned a single 221 - callback function. A void pointer parameter is provided, the value of which is 222 - passed to the callback function, the use of this pointer is user undefined: 223 - 224 - .. code-block:: c 225 - 226 - int vme_irq_request(struct vme_dev *dev, int level, int statid, 227 - void (*callback)(int, int, void *), void *priv); 228 - 229 - void vme_irq_free(struct vme_dev *dev, int level, int statid); 230 - 231 - The callback parameters are as follows. Care must be taken in writing a callback 232 - function, callback functions run in interrupt context: 361 + The function :c:func:`vme_irq_request` can be used to attach and 362 + :c:func:`vme_irq_free` to free a specific VME level and status ID combination. 363 + Any given combination can only be assigned a single callback function. A void 364 + pointer parameter is provided, the value of which is passed to the callback 365 + function, the use of this pointer is user undefined. The callback parameters are 366 + as follows. Care must be taken in writing a callback function, callback 367 + functions run in interrupt context: 233 368 234 369 .. code-block:: c 235 370 ··· 232 381 Interrupt Generation 233 382 ~~~~~~~~~~~~~~~~~~~~ 234 383 235 - The following function can be used to generate a VME interrupt at a given VME 236 - level and VME status ID: 237 - 238 - .. code-block:: c 239 - 240 - int vme_irq_generate(struct vme_dev *dev, int level, int statid); 384 + The function :c:func:`vme_irq_generate` can be used to generate a VME interrupt 385 + at a given VME level and VME status ID. 241 386 242 387 243 388 Location monitors ··· 246 399 Location Monitor Management 247 400 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 248 401 249 - The following functions are provided to request the use of a block of location 250 - monitors and to free them after they are no longer required: 251 - 252 - .. code-block:: c 253 - 254 - struct vme_resource * vme_lm_request(struct vme_dev *dev); 255 - 256 - void vme_lm_free(struct vme_resource * res); 257 - 258 - Each block may provide a number of location monitors, monitoring adjacent 259 - locations. The following function can be used to determine how many locations 260 - are provided: 261 - 262 - .. code-block:: c 263 - 264 - int vme_lm_count(struct vme_resource * res); 402 + The function :c:func:`vme_lm_request` is provided to request the use of a block 403 + of location monitors and :c:func:`vme_lm_free` to free them after they are no 404 + longer required. Each block may provide a number of location monitors, 405 + monitoring adjacent locations. The function :c:func:`vme_lm_count` can be used 406 + to determine how many locations are provided. 265 407 266 408 267 409 Location Monitor Configuration 268 410 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 269 411 270 - Once a bank of location monitors has been allocated, the following functions 271 - are provided to configure the location and mode of the location monitor: 272 - 273 - .. code-block:: c 274 - 275 - int vme_lm_set(struct vme_resource *res, unsigned long long base, 276 - u32 aspace, u32 cycle); 277 - 278 - int vme_lm_get(struct vme_resource *res, unsigned long long *base, 279 - u32 *aspace, u32 *cycle); 412 + Once a bank of location monitors has been allocated, the function 413 + :c:func:`vme_lm_set` is provided to configure the location and mode of the 414 + location monitor. The function :c:func:`vme_lm_get` can be used to retrieve 415 + existing settings. 280 416 281 417 282 418 Location Monitor Use 283 419 ~~~~~~~~~~~~~~~~~~~~ 284 420 285 - The following functions allow a callback to be attached and detached from each 286 - location monitor location. Each location monitor can monitor a number of 287 - adjacent locations: 288 - 289 - .. code-block:: c 290 - 291 - int vme_lm_attach(struct vme_resource *res, int num, 292 - void (*callback)(void *)); 293 - 294 - int vme_lm_detach(struct vme_resource *res, int num); 295 - 296 - The callback function is declared as follows. 421 + The function :c:func:`vme_lm_attach` enables a callback to be attached and 422 + :c:func:`vme_lm_detach` allows on to be detached from each location monitor 423 + location. Each location monitor can monitor a number of adjacent locations. The 424 + callback function is declared as follows. 297 425 298 426 .. code-block:: c 299 427 ··· 278 456 Slot Detection 279 457 -------------- 280 458 281 - This function returns the slot ID of the provided bridge. 282 - 283 - .. code-block:: c 284 - 285 - int vme_slot_num(struct vme_dev *dev); 459 + The function :c:func:`vme_slot_num` returns the slot ID of the provided bridge. 286 460 287 461 288 462 Bus Detection 289 463 ------------- 290 464 291 - This function returns the bus ID of the provided bridge. 465 + The function :c:func:`vme_bus_num` returns the bus ID of the provided bridge. 292 466 293 - .. code-block:: c 294 467 295 - int vme_bus_num(struct vme_dev *dev); 468 + VME API 469 + ------- 296 470 471 + .. kernel-doc:: include/linux/vme.h 472 + :internal: 473 + 474 + .. kernel-doc:: drivers/vme/vme.c 475 + :export:
-123
Documentation/extcon/porting-android-switch-class
··· 1 - 2 - Staging/Android Switch Class Porting Guide 3 - (linux/drivers/staging/android/switch) 4 - (c) Copyright 2012 Samsung Electronics 5 - 6 - AUTHORS 7 - MyungJoo Ham <myungjoo.ham@samsung.com> 8 - 9 - /***************************************************************** 10 - * CHAPTER 1. * 11 - * PORTING SWITCH CLASS DEVICE DRIVERS * 12 - *****************************************************************/ 13 - 14 - ****** STEP 1. Basic Functionality 15 - No extcon extended feature, but switch features only. 16 - 17 - - struct switch_dev (fed to switch_dev_register/unregister) 18 - @name: no change 19 - @dev: no change 20 - @index: drop (not used in switch device driver side anyway) 21 - @state: no change 22 - If you have used @state with magic numbers, keep it 23 - at this step. 24 - @print_name: no change but type change (switch_dev->extcon_dev) 25 - @print_state: no change but type change (switch_dev->extcon_dev) 26 - 27 - - switch_dev_register(sdev, dev) 28 - => extcon_dev_register(edev) 29 - : type change (sdev->edev) 30 - : remove second param('dev'). if edev has parent device, should store 31 - 'dev' to 'edev.dev.parent' before registering extcon device 32 - - switch_dev_unregister(sdev) 33 - => extcon_dev_unregister(edev) 34 - : no change but type change (sdev->edev) 35 - - switch_get_state(sdev) 36 - => extcon_get_state(edev) 37 - : no change but type change (sdev->edev) and (return: int->u32) 38 - - switch_set_state(sdev, state) 39 - => extcon_set_state(edev, state) 40 - : no change but type change (sdev->edev) and (state: int->u32) 41 - 42 - With this changes, the ex-switch extcon class device works as it once 43 - worked as switch class device. However, it will now have additional 44 - interfaces (both ABI and in-kernel API) and different ABI locations. 45 - However, if CONFIG_ANDROID is enabled without CONFIG_ANDROID_SWITCH, 46 - /sys/class/switch/* will be symbolically linked to /sys/class/extcon/ 47 - so that they are still compatible with legacy userspace processes. 48 - 49 - ****** STEP 2. Multistate (no more magic numbers in state value) 50 - Extcon's extended features for switch device drivers with 51 - complex features usually required magic numbers in state 52 - value of switch_dev. With extcon, such magic numbers that 53 - support multiple cables are no more required or supported. 54 - 55 - 1. Define cable names at edev->supported_cable. 56 - 2. (Recommended) remove print_state callback. 57 - 3. Use extcon_get_cable_state_(edev, index) or 58 - extcon_get_cable_state(edev, cable_name) instead of 59 - extcon_get_state(edev) if you intend to get a state of a specific 60 - cable. Same for set_state. This way, you can remove the usage of 61 - magic numbers in state value. 62 - 4. Use extcon_update_state() if you are updating specific bits of 63 - the state value. 64 - 65 - Example: a switch device driver w/ magic numbers for two cables. 66 - "0x00": no cables connected. 67 - "0x01": cable 1 connected 68 - "0x02": cable 2 connected 69 - "0x03": cable 1 and 2 connected 70 - 1. edev->supported_cable = {"1", "2", NULL}; 71 - 2. edev->print_state = NULL; 72 - 3. extcon_get_cable_state_(edev, 0) shows cable 1's state. 73 - extcon_get_cable_state(edev, "1") shows cable 1's state. 74 - extcon_set_cable_state_(edev, 1) sets cable 2's state. 75 - extcon_set_cable_state(edev, "2") sets cable 2's state 76 - 4. extcon_update_state(edev, 0x01, 0) sets the least bit's 0. 77 - 78 - ****** STEP 3. Notify other device drivers 79 - 80 - You can notify others of the cable attach/detach events with 81 - notifier chains. 82 - 83 - At the side of other device drivers (the extcon device itself 84 - does not need to get notified of its own events), there are two 85 - methods to register notifier_block for cable events: 86 - (a) for a specific cable or (b) for every cable. 87 - 88 - (a) extcon_register_interest(obj, extcon_name, cable_name, nb) 89 - Example: want to get news of "MAX8997_MUIC"'s "USB" cable 90 - 91 - obj = kzalloc(sizeof(struct extcon_specific_cable_nb), 92 - GFP_KERNEL); 93 - nb->notifier_call = the_callback_to_handle_usb; 94 - 95 - extcon_register_intereset(obj, "MAX8997_MUIC", "USB", nb); 96 - 97 - (b) extcon_register_notifier(edev, nb) 98 - Call nb for any changes in edev. 99 - 100 - Please note that in order to properly behave with method (a), 101 - the extcon device driver should support multistate feature (STEP 2). 102 - 103 - ****** STEP 4. Inter-cable relation (mutually exclusive) 104 - 105 - You can provide inter-cable mutually exclusiveness information 106 - for an extcon device. When cables A and B are declared to be mutually 107 - exclusive, the two cables cannot be in ATTACHED state simulteneously. 108 - 109 - 110 - /***************************************************************** 111 - * CHAPTER 2. * 112 - * PORTING USERSPACE w/ SWITCH CLASS DEVICE SUPPORT * 113 - *****************************************************************/ 114 - 115 - ****** ABI Location 116 - 117 - If "CONFIG_ANDROID" is enabled, /sys/class/switch/* are created 118 - as symbolic links to /sys/class/extcon/*. 119 - 120 - The two files of switch class, name and state, are provided with 121 - extcon, too. When the multistate support (STEP 2 of CHAPTER 1.) is 122 - not enabled or print_state callback is supplied, the output of 123 - state ABI is same with switch class.
+4
Documentation/w1/slaves/00-INDEX
··· 2 2 - This file 3 3 w1_therm 4 4 - The Maxim/Dallas Semiconductor ds18*20 temperature sensor. 5 + w1_ds2413 6 + - The Maxim/Dallas Semiconductor ds2413 dual channel addressable switch. 5 7 w1_ds2423 6 8 - The Maxim/Dallas Semiconductor ds2423 counter device. 9 + w1_ds2438 10 + - The Maxim/Dallas Semiconductor ds2438 smart battery monitor. 7 11 w1_ds28e04 8 12 - The Maxim/Dallas Semiconductor ds28e04 eeprom.
+50
Documentation/w1/slaves/w1_ds2413
··· 1 + Kernel driver w1_ds2413 2 + ======================= 3 + 4 + Supported chips: 5 + * Maxim DS2413 1-Wire Dual Channel Addressable Switch 6 + 7 + supported family codes: 8 + W1_FAMILY_DS2413 0x3A 9 + 10 + Author: Mariusz Bialonczyk <manio@skyboo.net> 11 + 12 + Description 13 + ----------- 14 + 15 + The DS2413 chip has two open-drain outputs (PIO A and PIO B). 16 + Support is provided through the sysfs files "output" and "state". 17 + 18 + Reading state 19 + ------------- 20 + The "state" file provides one-byte value which is in the same format as for 21 + the chip PIO_ACCESS_READ command (refer the datasheet for details): 22 + 23 + Bit 0: PIOA Pin State 24 + Bit 1: PIOA Output Latch State 25 + Bit 2: PIOB Pin State 26 + Bit 3: PIOB Output Latch State 27 + Bit 4-7: Complement of Bit 3 to Bit 0 (verified by the kernel module) 28 + 29 + This file is readonly. 30 + 31 + Writing output 32 + -------------- 33 + You can set the PIO pins using the "output" file. 34 + It is writable, you can write one-byte value to this sysfs file. 35 + Similarly the byte format is the same as for the PIO_ACCESS_WRITE command: 36 + 37 + Bit 0: PIOA 38 + Bit 1: PIOB 39 + Bit 2-7: No matter (driver will set it to "1"s) 40 + 41 + 42 + The chip has some kind of basic protection against transmission errors. 43 + When reading the state, there is a four complement bits. 44 + The driver is checking this complement, and when it is wrong then it is 45 + returning I/O error. 46 + 47 + When writing output, the master must repeat the PIO Output Data byte in 48 + its inverted form and it is waiting for a confirmation. 49 + If the write is unsuccessful for three times, the write also returns 50 + I/O error.
+63
Documentation/w1/slaves/w1_ds2438
··· 1 + Kernel driver w1_ds2438 2 + ======================= 3 + 4 + Supported chips: 5 + * Maxim DS2438 Smart Battery Monitor 6 + 7 + supported family codes: 8 + W1_FAMILY_DS2438 0x26 9 + 10 + Author: Mariusz Bialonczyk <manio@skyboo.net> 11 + 12 + Description 13 + ----------- 14 + 15 + The DS2438 chip provides several functions that are desirable to carry in 16 + a battery pack. It also has a 40 bytes of nonvolatile EEPROM. 17 + Because the ability of temperature, current and voltage measurement, the chip 18 + is also often used in weather stations and applications such as: rain gauge, 19 + wind speed/direction measuring, humidity sensing, etc. 20 + 21 + Current support is provided through the following sysfs files (all files 22 + except "iad" are readonly): 23 + 24 + "iad" 25 + ----- 26 + This file controls the 'Current A/D Control Bit' (IAD) in the 27 + Status/Configuration Register. 28 + Writing a zero value will clear the IAD bit and disables the current 29 + measurements. 30 + Writing value "1" is setting the IAD bit (enables the measurements). 31 + The IAD bit is enabled by default in the DS2438. 32 + 33 + When writing to sysfs file bits 2-7 are ignored, so it's safe to write ASCII. 34 + An I/O error is returned when there is a problem setting the new value. 35 + 36 + "page0" 37 + ------- 38 + This file provides full 8 bytes of the chip Page 0 (00h). 39 + This page contains the most frequently accessed information of the DS2438. 40 + Internally when this file is read, the additional CRC byte is also obtained 41 + from the slave device. If it is correct, the 8 bytes page data are passed 42 + to userspace, otherwise an I/O error is returned. 43 + 44 + "temperature" 45 + ------------- 46 + Opening and reading this file initiates the CONVERT_T (temperature conversion) 47 + command of the chip, afterwards the temperature is read from the device 48 + registers and provided as an ASCII decimal value. 49 + 50 + Important: The returned value has to be divided by 256 to get a real 51 + temperature in degrees Celsius. 52 + 53 + "vad", "vdd" 54 + ------------ 55 + Opening and reading this file initiates the CONVERT_V (voltage conversion) 56 + command of the chip. 57 + 58 + Depending on a sysfs filename a different input for the A/D will be selected: 59 + vad: general purpose A/D input (VAD) 60 + vdd: battery input (VDD) 61 + 62 + After the voltage conversion the value is returned as decimal ASCII. 63 + Note: The value is in mV, so to get a volts the value has to be divided by 10.
+4 -4
MAINTAINERS
··· 5161 5161 F: tools/firewire/ 5162 5162 5163 5163 FIRMWARE LOADER (request_firmware) 5164 - M: Ming Lei <ming.lei@canonical.com> 5165 5164 M: Luis R. Rodriguez <mcgrof@kernel.org> 5166 5165 L: linux-kernel@vger.kernel.org 5167 5166 S: Maintained ··· 5190 5191 K: fmc_d.*register 5191 5192 5192 5193 FPGA MANAGER FRAMEWORK 5193 - M: Alan Tull <atull@opensource.altera.com> 5194 + M: Alan Tull <atull@kernel.org> 5194 5195 R: Moritz Fischer <moritz.fischer@ettus.com> 5195 5196 L: linux-fpga@vger.kernel.org 5196 5197 S: Maintained 5197 5198 T: git git://git.kernel.org/pub/scm/linux/kernel/git/atull/linux-fpga.git 5199 + F: Documentation/fpga/ 5200 + F: Documentation/devicetree/bindings/fpga/ 5198 5201 F: drivers/fpga/ 5199 - F: include/linux/fpga/fpga-mgr.h 5202 + F: include/linux/fpga/ 5200 5203 W: http://www.rocketboards.org 5201 5204 5202 5205 FPU EMULATOR ··· 9132 9131 9133 9132 NVMEM FRAMEWORK 9134 9133 M: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> 9135 - M: Maxime Ripard <maxime.ripard@free-electrons.com> 9136 9134 S: Maintained 9137 9135 F: drivers/nvmem/ 9138 9136 F: Documentation/devicetree/bindings/nvmem/
+26
arch/arm/mach-ep93xx/ts72xx.c
··· 210 210 .phy_id = 1, 211 211 }; 212 212 213 + #if IS_ENABLED(CONFIG_FPGA_MGR_TS73XX) 214 + 215 + /* Relative to EP93XX_CS1_PHYS_BASE */ 216 + #define TS73XX_FPGA_LOADER_BASE 0x03c00000 217 + 218 + static struct resource ts73xx_fpga_resources[] = { 219 + { 220 + .start = EP93XX_CS1_PHYS_BASE + TS73XX_FPGA_LOADER_BASE, 221 + .end = EP93XX_CS1_PHYS_BASE + TS73XX_FPGA_LOADER_BASE + 1, 222 + .flags = IORESOURCE_MEM, 223 + }, 224 + }; 225 + 226 + static struct platform_device ts73xx_fpga_device = { 227 + .name = "ts73xx-fpga-mgr", 228 + .id = -1, 229 + .resource = ts73xx_fpga_resources, 230 + .num_resources = ARRAY_SIZE(ts73xx_fpga_resources), 231 + }; 232 + 233 + #endif 234 + 213 235 static void __init ts72xx_init_machine(void) 214 236 { 215 237 ep93xx_init_devices(); ··· 240 218 platform_device_register(&ts72xx_wdt_device); 241 219 242 220 ep93xx_register_eth(&ts72xx_eth_data, 1); 221 + #if IS_ENABLED(CONFIG_FPGA_MGR_TS73XX) 222 + if (board_is_ts7300()) 223 + platform_device_register(&ts73xx_fpga_device); 224 + #endif 243 225 } 244 226 245 227 MACHINE_START(TS72XX, "Technologic Systems TS-72xx SBC")
+1 -1
arch/x86/hyperv/hv_init.c
··· 25 25 #include <linux/vmalloc.h> 26 26 #include <linux/mm.h> 27 27 #include <linux/clockchips.h> 28 - 28 + #include <linux/hyperv.h> 29 29 30 30 #ifdef CONFIG_HYPERV_TSCPAGE 31 31
+6 -1
arch/x86/include/uapi/asm/hyperv.h
··· 124 124 * Recommend using hypercall for address space switches rather 125 125 * than MOV to CR3 instruction 126 126 */ 127 - #define HV_X64_MWAIT_RECOMMENDED (1 << 0) 127 + #define HV_X64_AS_SWITCH_RECOMMENDED (1 << 0) 128 128 /* Recommend using hypercall for local TLB flushes rather 129 129 * than INVLPG or MOV to CR3 instructions */ 130 130 #define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1 << 1) ··· 146 146 * timely delivery of external interrupts 147 147 */ 148 148 #define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5) 149 + 150 + /* 151 + * Virtual APIC support 152 + */ 153 + #define HV_X64_DEPRECATING_AEOI_RECOMMENDED (1 << 9) 149 154 150 155 /* 151 156 * Crash notification flag.
+3
arch/x86/kernel/cpu/mshyperv.c
··· 49 49 if (vmbus_handler) 50 50 vmbus_handler(); 51 51 52 + if (ms_hyperv.hints & HV_X64_DEPRECATING_AEOI_RECOMMENDED) 53 + ack_APIC_irq(); 54 + 52 55 exiting_irq(); 53 56 set_irq_regs(old_regs); 54 57 }
+1 -1
drivers/android/Kconfig
··· 22 22 config ANDROID_BINDER_DEVICES 23 23 string "Android Binder devices" 24 24 depends on ANDROID_BINDER_IPC 25 - default "binder" 25 + default "binder,hwbinder" 26 26 ---help--- 27 27 Default value for the binder.devices parameter. 28 28
+304
drivers/auxdisplay/Kconfig
··· 13 13 14 14 If you say N, all options in this submenu will be skipped and disabled. 15 15 16 + config CHARLCD 17 + tristate "Character LCD core support" if COMPILE_TEST 18 + 16 19 if AUXDISPLAY 20 + 21 + config HD44780 22 + tristate "HD44780 Character LCD support" 23 + depends on GPIOLIB || COMPILE_TEST 24 + select CHARLCD 25 + ---help--- 26 + Enable support for Character LCDs using a HD44780 controller. 27 + The LCD is accessible through the /dev/lcd char device (10, 156). 28 + This code can either be compiled as a module, or linked into the 29 + kernel and started at boot. 30 + If you don't understand what all this is about, say N. 17 31 18 32 config KS0108 19 33 tristate "KS0108 LCD Controller" ··· 156 142 LED controller driver with keyscan. 157 143 158 144 endif # AUXDISPLAY 145 + 146 + config ARM_CHARLCD 147 + bool "ARM Ltd. Character LCD Driver" 148 + depends on PLAT_VERSATILE 149 + help 150 + This is a driver for the character LCD found on the ARM Ltd. 151 + Versatile and RealView Platform Baseboards. It doesn't do 152 + very much more than display the text "ARM Linux" on the first 153 + line and the Linux version on the second line, but that's 154 + still useful. 155 + 156 + config PANEL 157 + tristate "Parallel port LCD/Keypad Panel support" 158 + depends on PARPORT 159 + select CHARLCD 160 + ---help--- 161 + Say Y here if you have an HD44780 or KS-0074 LCD connected to your 162 + parallel port. This driver also features 4 and 6-key keypads. The LCD 163 + is accessible through the /dev/lcd char device (10, 156), and the 164 + keypad through /dev/keypad (10, 185). This code can either be 165 + compiled as a module, or linked into the kernel and started at boot. 166 + If you don't understand what all this is about, say N. 167 + 168 + if PANEL 169 + 170 + config PANEL_PARPORT 171 + int "Default parallel port number (0=LPT1)" 172 + range 0 255 173 + default "0" 174 + ---help--- 175 + This is the index of the parallel port the panel is connected to. One 176 + driver instance only supports one parallel port, so if your keypad 177 + and LCD are connected to two separate ports, you have to start two 178 + modules with different arguments. Numbering starts with '0' for LPT1, 179 + and so on. 180 + 181 + config PANEL_PROFILE 182 + int "Default panel profile (0-5, 0=custom)" 183 + range 0 5 184 + default "5" 185 + ---help--- 186 + To ease configuration, the driver supports different configuration 187 + profiles for past and recent wirings. These profiles can also be 188 + used to define an approximative configuration, completed by a few 189 + other options. Here are the profiles : 190 + 191 + 0 = custom (see further) 192 + 1 = 2x16 parallel LCD, old keypad 193 + 2 = 2x16 serial LCD (KS-0074), new keypad 194 + 3 = 2x16 parallel LCD (Hantronix), no keypad 195 + 4 = 2x16 parallel LCD (Nexcom NSA1045) with Nexcom's keypad 196 + 5 = 2x40 parallel LCD (old one), with old keypad 197 + 198 + Custom configurations allow you to define how your display is 199 + wired to the parallel port, and how it works. This is only intended 200 + for experts. 201 + 202 + config PANEL_KEYPAD 203 + depends on PANEL_PROFILE="0" 204 + int "Keypad type (0=none, 1=old 6 keys, 2=new 6 keys, 3=Nexcom 4 keys)" 205 + range 0 3 206 + default 0 207 + ---help--- 208 + This enables and configures a keypad connected to the parallel port. 209 + The keys will be read from character device 10,185. Valid values are : 210 + 211 + 0 : do not enable this driver 212 + 1 : old 6 keys keypad 213 + 2 : new 6 keys keypad, as used on the server at www.ant-computing.com 214 + 3 : Nexcom NSA1045's 4 keys keypad 215 + 216 + New profiles can be described in the driver source. The driver also 217 + supports simultaneous keys pressed when the keypad supports them. 218 + 219 + config PANEL_LCD 220 + depends on PANEL_PROFILE="0" 221 + int "LCD type (0=none, 1=custom, 2=old //, 3=ks0074, 4=hantronix, 5=Nexcom)" 222 + range 0 5 223 + default 0 224 + ---help--- 225 + This enables and configures an LCD connected to the parallel port. 226 + The driver includes an interpreter for escape codes starting with 227 + '\e[L' which are specific to the LCD, and a few ANSI codes. The 228 + driver will be registered as character device 10,156, usually 229 + under the name '/dev/lcd'. There are a total of 6 supported types : 230 + 231 + 0 : do not enable the driver 232 + 1 : custom configuration and wiring (see further) 233 + 2 : 2x16 & 2x40 parallel LCD (old wiring) 234 + 3 : 2x16 serial LCD (KS-0074 based) 235 + 4 : 2x16 parallel LCD (Hantronix wiring) 236 + 5 : 2x16 parallel LCD (Nexcom wiring) 237 + 238 + When type '1' is specified, other options will appear to configure 239 + more precise aspects (wiring, dimensions, protocol, ...). Please note 240 + that those values changed from the 2.4 driver for better consistency. 241 + 242 + config PANEL_LCD_HEIGHT 243 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 244 + int "Number of lines on the LCD (1-2)" 245 + range 1 2 246 + default 2 247 + ---help--- 248 + This is the number of visible character lines on the LCD in custom profile. 249 + It can either be 1 or 2. 250 + 251 + config PANEL_LCD_WIDTH 252 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 253 + int "Number of characters per line on the LCD (1-40)" 254 + range 1 40 255 + default 40 256 + ---help--- 257 + This is the number of characters per line on the LCD in custom profile. 258 + Common values are 16,20,24,40. 259 + 260 + config PANEL_LCD_BWIDTH 261 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 262 + int "Internal LCD line width (1-40, 40 by default)" 263 + range 1 40 264 + default 40 265 + ---help--- 266 + Most LCDs use a standard controller which supports hardware lines of 40 267 + characters, although sometimes only 16, 20 or 24 of them are really wired 268 + to the terminal. This results in some non-visible but addressable characters, 269 + and is the case for most parallel LCDs. Other LCDs, and some serial ones, 270 + however, use the same line width internally as what is visible. The KS0074 271 + for example, uses 16 characters per line for 16 visible characters per line. 272 + 273 + This option lets you configure the value used by your LCD in 'custom' profile. 274 + If you don't know, put '40' here. 275 + 276 + config PANEL_LCD_HWIDTH 277 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 278 + int "Hardware LCD line width (1-64, 64 by default)" 279 + range 1 64 280 + default 64 281 + ---help--- 282 + Most LCDs use a single address bit to differentiate line 0 and line 1. Since 283 + some of them need to be able to address 40 chars with the lower bits, they 284 + often use the immediately superior power of 2, which is 64, to address the 285 + next line. 286 + 287 + If you don't know what your LCD uses, in doubt let 16 here for a 2x16, and 288 + 64 here for a 2x40. 289 + 290 + config PANEL_LCD_CHARSET 291 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 292 + int "LCD character set (0=normal, 1=KS0074)" 293 + range 0 1 294 + default 0 295 + ---help--- 296 + Some controllers such as the KS0074 use a somewhat strange character set 297 + where many symbols are at unusual places. The driver knows how to map 298 + 'standard' ASCII characters to the character sets used by these controllers. 299 + Valid values are : 300 + 301 + 0 : normal (untranslated) character set 302 + 1 : KS0074 character set 303 + 304 + If you don't know, use the normal one (0). 305 + 306 + config PANEL_LCD_PROTO 307 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 308 + int "LCD communication mode (0=parallel 8 bits, 1=serial)" 309 + range 0 1 310 + default 0 311 + ---help--- 312 + This driver now supports any serial or parallel LCD wired to a parallel 313 + port. But before assigning signals, the driver needs to know if it will 314 + be driving a serial LCD or a parallel one. Serial LCDs only use 2 wires 315 + (SDA/SCL), while parallel ones use 2 or 3 wires for the control signals 316 + (E, RS, sometimes RW), and 4 or 8 for the data. Use 0 here for a 8 bits 317 + parallel LCD, and 1 for a serial LCD. 318 + 319 + config PANEL_LCD_PIN_E 320 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 321 + int "Parallel port pin number & polarity connected to the LCD E signal (-17...17) " 322 + range -17 17 323 + default 14 324 + ---help--- 325 + This describes the number of the parallel port pin to which the LCD 'E' 326 + signal has been connected. It can be : 327 + 328 + 0 : no connection (eg: connected to ground) 329 + 1..17 : directly connected to any of these pins on the DB25 plug 330 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 331 + 332 + Default for the 'E' pin in custom profile is '14' (AUTOFEED). 333 + 334 + config PANEL_LCD_PIN_RS 335 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 336 + int "Parallel port pin number & polarity connected to the LCD RS signal (-17...17) " 337 + range -17 17 338 + default 17 339 + ---help--- 340 + This describes the number of the parallel port pin to which the LCD 'RS' 341 + signal has been connected. It can be : 342 + 343 + 0 : no connection (eg: connected to ground) 344 + 1..17 : directly connected to any of these pins on the DB25 plug 345 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 346 + 347 + Default for the 'RS' pin in custom profile is '17' (SELECT IN). 348 + 349 + config PANEL_LCD_PIN_RW 350 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 351 + int "Parallel port pin number & polarity connected to the LCD RW signal (-17...17) " 352 + range -17 17 353 + default 16 354 + ---help--- 355 + This describes the number of the parallel port pin to which the LCD 'RW' 356 + signal has been connected. It can be : 357 + 358 + 0 : no connection (eg: connected to ground) 359 + 1..17 : directly connected to any of these pins on the DB25 plug 360 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 361 + 362 + Default for the 'RW' pin in custom profile is '16' (INIT). 363 + 364 + config PANEL_LCD_PIN_SCL 365 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO!="0" 366 + int "Parallel port pin number & polarity connected to the LCD SCL signal (-17...17) " 367 + range -17 17 368 + default 1 369 + ---help--- 370 + This describes the number of the parallel port pin to which the serial 371 + LCD 'SCL' signal has been connected. It can be : 372 + 373 + 0 : no connection (eg: connected to ground) 374 + 1..17 : directly connected to any of these pins on the DB25 plug 375 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 376 + 377 + Default for the 'SCL' pin in custom profile is '1' (STROBE). 378 + 379 + config PANEL_LCD_PIN_SDA 380 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO!="0" 381 + int "Parallel port pin number & polarity connected to the LCD SDA signal (-17...17) " 382 + range -17 17 383 + default 2 384 + ---help--- 385 + This describes the number of the parallel port pin to which the serial 386 + LCD 'SDA' signal has been connected. It can be : 387 + 388 + 0 : no connection (eg: connected to ground) 389 + 1..17 : directly connected to any of these pins on the DB25 plug 390 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 391 + 392 + Default for the 'SDA' pin in custom profile is '2' (D0). 393 + 394 + config PANEL_LCD_PIN_BL 395 + depends on PANEL_PROFILE="0" && PANEL_LCD="1" 396 + int "Parallel port pin number & polarity connected to the LCD backlight signal (-17...17) " 397 + range -17 17 398 + default 0 399 + ---help--- 400 + This describes the number of the parallel port pin to which the LCD 'BL' signal 401 + has been connected. It can be : 402 + 403 + 0 : no connection (eg: connected to ground) 404 + 1..17 : directly connected to any of these pins on the DB25 plug 405 + -1..-17 : connected to the same pin through an inverter (eg: transistor). 406 + 407 + Default for the 'BL' pin in custom profile is '0' (uncontrolled). 408 + 409 + config PANEL_CHANGE_MESSAGE 410 + bool "Change LCD initialization message ?" 411 + default "n" 412 + ---help--- 413 + This allows you to replace the boot message indicating the kernel version 414 + and the driver version with a custom message. This is useful on appliances 415 + where a simple 'Starting system' message can be enough to stop a customer 416 + from worrying. 417 + 418 + If you say 'Y' here, you'll be able to choose a message yourself. Otherwise, 419 + say 'N' and keep the default message with the version. 420 + 421 + config PANEL_BOOT_MESSAGE 422 + depends on PANEL_CHANGE_MESSAGE="y" 423 + string "New initialization message" 424 + default "" 425 + ---help--- 426 + This allows you to replace the boot message indicating the kernel version 427 + and the driver version with a custom message. This is useful on appliances 428 + where a simple 'Starting system' message can be enough to stop a customer 429 + from worrying. 430 + 431 + An empty message will only clear the display at driver init time. Any other 432 + printf()-formatted message is valid with newline and escape codes. 433 + 434 + endif # PANEL
+4
drivers/auxdisplay/Makefile
··· 2 2 # Makefile for the kernel auxiliary displays device drivers. 3 3 # 4 4 5 + obj-$(CONFIG_CHARLCD) += charlcd.o 6 + obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o 5 7 obj-$(CONFIG_KS0108) += ks0108.o 6 8 obj-$(CONFIG_CFAG12864B) += cfag12864b.o cfag12864bfb.o 7 9 obj-$(CONFIG_IMG_ASCII_LCD) += img-ascii-lcd.o 10 + obj-$(CONFIG_HD44780) += hd44780.o 8 11 obj-$(CONFIG_HT16K33) += ht16k33.o 12 + obj-$(CONFIG_PANEL) += panel.o
+818
drivers/auxdisplay/charlcd.c
··· 1 + /* 2 + * Character LCD driver for Linux 3 + * 4 + * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> 5 + * Copyright (C) 2016-2017 Glider bvba 6 + * 7 + * This program is free software; you can redistribute it and/or 8 + * modify it under the terms of the GNU General Public License 9 + * as published by the Free Software Foundation; either version 10 + * 2 of the License, or (at your option) any later version. 11 + */ 12 + 13 + #include <linux/atomic.h> 14 + #include <linux/delay.h> 15 + #include <linux/fs.h> 16 + #include <linux/miscdevice.h> 17 + #include <linux/module.h> 18 + #include <linux/notifier.h> 19 + #include <linux/reboot.h> 20 + #include <linux/slab.h> 21 + #include <linux/uaccess.h> 22 + #include <linux/workqueue.h> 23 + 24 + #include <generated/utsrelease.h> 25 + 26 + #include <misc/charlcd.h> 27 + 28 + #define LCD_MINOR 156 29 + 30 + #define DEFAULT_LCD_BWIDTH 40 31 + #define DEFAULT_LCD_HWIDTH 64 32 + 33 + /* Keep the backlight on this many seconds for each flash */ 34 + #define LCD_BL_TEMPO_PERIOD 4 35 + 36 + #define LCD_FLAG_B 0x0004 /* Blink on */ 37 + #define LCD_FLAG_C 0x0008 /* Cursor on */ 38 + #define LCD_FLAG_D 0x0010 /* Display on */ 39 + #define LCD_FLAG_F 0x0020 /* Large font mode */ 40 + #define LCD_FLAG_N 0x0040 /* 2-rows mode */ 41 + #define LCD_FLAG_L 0x0080 /* Backlight enabled */ 42 + 43 + /* LCD commands */ 44 + #define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */ 45 + 46 + #define LCD_CMD_ENTRY_MODE 0x04 /* Set entry mode */ 47 + #define LCD_CMD_CURSOR_INC 0x02 /* Increment cursor */ 48 + 49 + #define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */ 50 + #define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */ 51 + #define LCD_CMD_CURSOR_ON 0x02 /* Set cursor on */ 52 + #define LCD_CMD_BLINK_ON 0x01 /* Set blink on */ 53 + 54 + #define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */ 55 + #define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */ 56 + #define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */ 57 + 58 + #define LCD_CMD_FUNCTION_SET 0x20 /* Set function */ 59 + #define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */ 60 + #define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */ 61 + #define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */ 62 + 63 + #define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */ 64 + 65 + #define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */ 66 + 67 + #define LCD_ESCAPE_LEN 24 /* Max chars for LCD escape command */ 68 + #define LCD_ESCAPE_CHAR 27 /* Use char 27 for escape command */ 69 + 70 + struct charlcd_priv { 71 + struct charlcd lcd; 72 + 73 + struct delayed_work bl_work; 74 + struct mutex bl_tempo_lock; /* Protects access to bl_tempo */ 75 + bool bl_tempo; 76 + 77 + bool must_clear; 78 + 79 + /* contains the LCD config state */ 80 + unsigned long int flags; 81 + 82 + /* Contains the LCD X and Y offset */ 83 + struct { 84 + unsigned long int x; 85 + unsigned long int y; 86 + } addr; 87 + 88 + /* Current escape sequence and it's length or -1 if outside */ 89 + struct { 90 + char buf[LCD_ESCAPE_LEN + 1]; 91 + int len; 92 + } esc_seq; 93 + 94 + unsigned long long drvdata[0]; 95 + }; 96 + 97 + #define to_priv(p) container_of(p, struct charlcd_priv, lcd) 98 + 99 + /* Device single-open policy control */ 100 + static atomic_t charlcd_available = ATOMIC_INIT(1); 101 + 102 + /* sleeps that many milliseconds with a reschedule */ 103 + static void long_sleep(int ms) 104 + { 105 + if (in_interrupt()) 106 + mdelay(ms); 107 + else 108 + schedule_timeout_interruptible(msecs_to_jiffies(ms)); 109 + } 110 + 111 + /* turn the backlight on or off */ 112 + static void charlcd_backlight(struct charlcd *lcd, int on) 113 + { 114 + struct charlcd_priv *priv = to_priv(lcd); 115 + 116 + if (!lcd->ops->backlight) 117 + return; 118 + 119 + mutex_lock(&priv->bl_tempo_lock); 120 + if (!priv->bl_tempo) 121 + lcd->ops->backlight(lcd, on); 122 + mutex_unlock(&priv->bl_tempo_lock); 123 + } 124 + 125 + static void charlcd_bl_off(struct work_struct *work) 126 + { 127 + struct delayed_work *dwork = to_delayed_work(work); 128 + struct charlcd_priv *priv = 129 + container_of(dwork, struct charlcd_priv, bl_work); 130 + 131 + mutex_lock(&priv->bl_tempo_lock); 132 + if (priv->bl_tempo) { 133 + priv->bl_tempo = false; 134 + if (!(priv->flags & LCD_FLAG_L)) 135 + priv->lcd.ops->backlight(&priv->lcd, 0); 136 + } 137 + mutex_unlock(&priv->bl_tempo_lock); 138 + } 139 + 140 + /* turn the backlight on for a little while */ 141 + void charlcd_poke(struct charlcd *lcd) 142 + { 143 + struct charlcd_priv *priv = to_priv(lcd); 144 + 145 + if (!lcd->ops->backlight) 146 + return; 147 + 148 + cancel_delayed_work_sync(&priv->bl_work); 149 + 150 + mutex_lock(&priv->bl_tempo_lock); 151 + if (!priv->bl_tempo && !(priv->flags & LCD_FLAG_L)) 152 + lcd->ops->backlight(lcd, 1); 153 + priv->bl_tempo = true; 154 + schedule_delayed_work(&priv->bl_work, LCD_BL_TEMPO_PERIOD * HZ); 155 + mutex_unlock(&priv->bl_tempo_lock); 156 + } 157 + EXPORT_SYMBOL_GPL(charlcd_poke); 158 + 159 + static void charlcd_gotoxy(struct charlcd *lcd) 160 + { 161 + struct charlcd_priv *priv = to_priv(lcd); 162 + unsigned int addr; 163 + 164 + /* 165 + * we force the cursor to stay at the end of the 166 + * line if it wants to go farther 167 + */ 168 + addr = priv->addr.x < lcd->bwidth ? priv->addr.x & (lcd->hwidth - 1) 169 + : lcd->bwidth - 1; 170 + if (priv->addr.y & 1) 171 + addr += lcd->hwidth; 172 + if (priv->addr.y & 2) 173 + addr += lcd->bwidth; 174 + lcd->ops->write_cmd(lcd, LCD_CMD_SET_DDRAM_ADDR | addr); 175 + } 176 + 177 + static void charlcd_home(struct charlcd *lcd) 178 + { 179 + struct charlcd_priv *priv = to_priv(lcd); 180 + 181 + priv->addr.x = 0; 182 + priv->addr.y = 0; 183 + charlcd_gotoxy(lcd); 184 + } 185 + 186 + static void charlcd_print(struct charlcd *lcd, char c) 187 + { 188 + struct charlcd_priv *priv = to_priv(lcd); 189 + 190 + if (priv->addr.x < lcd->bwidth) { 191 + if (lcd->char_conv) 192 + c = lcd->char_conv[(unsigned char)c]; 193 + lcd->ops->write_data(lcd, c); 194 + priv->addr.x++; 195 + } 196 + /* prevents the cursor from wrapping onto the next line */ 197 + if (priv->addr.x == lcd->bwidth) 198 + charlcd_gotoxy(lcd); 199 + } 200 + 201 + static void charlcd_clear_fast(struct charlcd *lcd) 202 + { 203 + int pos; 204 + 205 + charlcd_home(lcd); 206 + 207 + if (lcd->ops->clear_fast) 208 + lcd->ops->clear_fast(lcd); 209 + else 210 + for (pos = 0; pos < min(2, lcd->height) * lcd->hwidth; pos++) 211 + lcd->ops->write_data(lcd, ' '); 212 + 213 + charlcd_home(lcd); 214 + } 215 + 216 + /* clears the display and resets X/Y */ 217 + static void charlcd_clear_display(struct charlcd *lcd) 218 + { 219 + struct charlcd_priv *priv = to_priv(lcd); 220 + 221 + lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CLEAR); 222 + priv->addr.x = 0; 223 + priv->addr.y = 0; 224 + /* we must wait a few milliseconds (15) */ 225 + long_sleep(15); 226 + } 227 + 228 + static int charlcd_init_display(struct charlcd *lcd) 229 + { 230 + void (*write_cmd_raw)(struct charlcd *lcd, int cmd); 231 + struct charlcd_priv *priv = to_priv(lcd); 232 + u8 init; 233 + 234 + if (lcd->ifwidth != 4 && lcd->ifwidth != 8) 235 + return -EINVAL; 236 + 237 + priv->flags = ((lcd->height > 1) ? LCD_FLAG_N : 0) | LCD_FLAG_D | 238 + LCD_FLAG_C | LCD_FLAG_B; 239 + 240 + long_sleep(20); /* wait 20 ms after power-up for the paranoid */ 241 + 242 + /* 243 + * 8-bit mode, 1 line, small fonts; let's do it 3 times, to make sure 244 + * the LCD is in 8-bit mode afterwards 245 + */ 246 + init = LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS; 247 + if (lcd->ifwidth == 4) { 248 + init >>= 4; 249 + write_cmd_raw = lcd->ops->write_cmd_raw4; 250 + } else { 251 + write_cmd_raw = lcd->ops->write_cmd; 252 + } 253 + write_cmd_raw(lcd, init); 254 + long_sleep(10); 255 + write_cmd_raw(lcd, init); 256 + long_sleep(10); 257 + write_cmd_raw(lcd, init); 258 + long_sleep(10); 259 + 260 + if (lcd->ifwidth == 4) { 261 + /* Switch to 4-bit mode, 1 line, small fonts */ 262 + lcd->ops->write_cmd_raw4(lcd, LCD_CMD_FUNCTION_SET >> 4); 263 + long_sleep(10); 264 + } 265 + 266 + /* set font height and lines number */ 267 + lcd->ops->write_cmd(lcd, 268 + LCD_CMD_FUNCTION_SET | 269 + ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) | 270 + ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) | 271 + ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)); 272 + long_sleep(10); 273 + 274 + /* display off, cursor off, blink off */ 275 + lcd->ops->write_cmd(lcd, LCD_CMD_DISPLAY_CTRL); 276 + long_sleep(10); 277 + 278 + lcd->ops->write_cmd(lcd, 279 + LCD_CMD_DISPLAY_CTRL | /* set display mode */ 280 + ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) | 281 + ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) | 282 + ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)); 283 + 284 + charlcd_backlight(lcd, (priv->flags & LCD_FLAG_L) ? 1 : 0); 285 + 286 + long_sleep(10); 287 + 288 + /* entry mode set : increment, cursor shifting */ 289 + lcd->ops->write_cmd(lcd, LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC); 290 + 291 + charlcd_clear_display(lcd); 292 + return 0; 293 + } 294 + 295 + /* 296 + * These are the file operation function for user access to /dev/lcd 297 + * This function can also be called from inside the kernel, by 298 + * setting file and ppos to NULL. 299 + * 300 + */ 301 + 302 + static inline int handle_lcd_special_code(struct charlcd *lcd) 303 + { 304 + struct charlcd_priv *priv = to_priv(lcd); 305 + 306 + /* LCD special codes */ 307 + 308 + int processed = 0; 309 + 310 + char *esc = priv->esc_seq.buf + 2; 311 + int oldflags = priv->flags; 312 + 313 + /* check for display mode flags */ 314 + switch (*esc) { 315 + case 'D': /* Display ON */ 316 + priv->flags |= LCD_FLAG_D; 317 + processed = 1; 318 + break; 319 + case 'd': /* Display OFF */ 320 + priv->flags &= ~LCD_FLAG_D; 321 + processed = 1; 322 + break; 323 + case 'C': /* Cursor ON */ 324 + priv->flags |= LCD_FLAG_C; 325 + processed = 1; 326 + break; 327 + case 'c': /* Cursor OFF */ 328 + priv->flags &= ~LCD_FLAG_C; 329 + processed = 1; 330 + break; 331 + case 'B': /* Blink ON */ 332 + priv->flags |= LCD_FLAG_B; 333 + processed = 1; 334 + break; 335 + case 'b': /* Blink OFF */ 336 + priv->flags &= ~LCD_FLAG_B; 337 + processed = 1; 338 + break; 339 + case '+': /* Back light ON */ 340 + priv->flags |= LCD_FLAG_L; 341 + processed = 1; 342 + break; 343 + case '-': /* Back light OFF */ 344 + priv->flags &= ~LCD_FLAG_L; 345 + processed = 1; 346 + break; 347 + case '*': /* Flash back light */ 348 + charlcd_poke(lcd); 349 + processed = 1; 350 + break; 351 + case 'f': /* Small Font */ 352 + priv->flags &= ~LCD_FLAG_F; 353 + processed = 1; 354 + break; 355 + case 'F': /* Large Font */ 356 + priv->flags |= LCD_FLAG_F; 357 + processed = 1; 358 + break; 359 + case 'n': /* One Line */ 360 + priv->flags &= ~LCD_FLAG_N; 361 + processed = 1; 362 + break; 363 + case 'N': /* Two Lines */ 364 + priv->flags |= LCD_FLAG_N; 365 + break; 366 + case 'l': /* Shift Cursor Left */ 367 + if (priv->addr.x > 0) { 368 + /* back one char if not at end of line */ 369 + if (priv->addr.x < lcd->bwidth) 370 + lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); 371 + priv->addr.x--; 372 + } 373 + processed = 1; 374 + break; 375 + case 'r': /* shift cursor right */ 376 + if (priv->addr.x < lcd->width) { 377 + /* allow the cursor to pass the end of the line */ 378 + if (priv->addr.x < (lcd->bwidth - 1)) 379 + lcd->ops->write_cmd(lcd, 380 + LCD_CMD_SHIFT | LCD_CMD_SHIFT_RIGHT); 381 + priv->addr.x++; 382 + } 383 + processed = 1; 384 + break; 385 + case 'L': /* shift display left */ 386 + lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT); 387 + processed = 1; 388 + break; 389 + case 'R': /* shift display right */ 390 + lcd->ops->write_cmd(lcd, 391 + LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT | 392 + LCD_CMD_SHIFT_RIGHT); 393 + processed = 1; 394 + break; 395 + case 'k': { /* kill end of line */ 396 + int x; 397 + 398 + for (x = priv->addr.x; x < lcd->bwidth; x++) 399 + lcd->ops->write_data(lcd, ' '); 400 + 401 + /* restore cursor position */ 402 + charlcd_gotoxy(lcd); 403 + processed = 1; 404 + break; 405 + } 406 + case 'I': /* reinitialize display */ 407 + charlcd_init_display(lcd); 408 + processed = 1; 409 + break; 410 + case 'G': { 411 + /* Generator : LGcxxxxx...xx; must have <c> between '0' 412 + * and '7', representing the numerical ASCII code of the 413 + * redefined character, and <xx...xx> a sequence of 16 414 + * hex digits representing 8 bytes for each character. 415 + * Most LCDs will only use 5 lower bits of the 7 first 416 + * bytes. 417 + */ 418 + 419 + unsigned char cgbytes[8]; 420 + unsigned char cgaddr; 421 + int cgoffset; 422 + int shift; 423 + char value; 424 + int addr; 425 + 426 + if (!strchr(esc, ';')) 427 + break; 428 + 429 + esc++; 430 + 431 + cgaddr = *(esc++) - '0'; 432 + if (cgaddr > 7) { 433 + processed = 1; 434 + break; 435 + } 436 + 437 + cgoffset = 0; 438 + shift = 0; 439 + value = 0; 440 + while (*esc && cgoffset < 8) { 441 + shift ^= 4; 442 + if (*esc >= '0' && *esc <= '9') { 443 + value |= (*esc - '0') << shift; 444 + } else if (*esc >= 'A' && *esc <= 'Z') { 445 + value |= (*esc - 'A' + 10) << shift; 446 + } else if (*esc >= 'a' && *esc <= 'z') { 447 + value |= (*esc - 'a' + 10) << shift; 448 + } else { 449 + esc++; 450 + continue; 451 + } 452 + 453 + if (shift == 0) { 454 + cgbytes[cgoffset++] = value; 455 + value = 0; 456 + } 457 + 458 + esc++; 459 + } 460 + 461 + lcd->ops->write_cmd(lcd, LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8)); 462 + for (addr = 0; addr < cgoffset; addr++) 463 + lcd->ops->write_data(lcd, cgbytes[addr]); 464 + 465 + /* ensures that we stop writing to CGRAM */ 466 + charlcd_gotoxy(lcd); 467 + processed = 1; 468 + break; 469 + } 470 + case 'x': /* gotoxy : LxXXX[yYYY]; */ 471 + case 'y': /* gotoxy : LyYYY[xXXX]; */ 472 + if (!strchr(esc, ';')) 473 + break; 474 + 475 + while (*esc) { 476 + if (*esc == 'x') { 477 + esc++; 478 + if (kstrtoul(esc, 10, &priv->addr.x) < 0) 479 + break; 480 + } else if (*esc == 'y') { 481 + esc++; 482 + if (kstrtoul(esc, 10, &priv->addr.y) < 0) 483 + break; 484 + } else { 485 + break; 486 + } 487 + } 488 + 489 + charlcd_gotoxy(lcd); 490 + processed = 1; 491 + break; 492 + } 493 + 494 + /* TODO: This indent party here got ugly, clean it! */ 495 + /* Check whether one flag was changed */ 496 + if (oldflags == priv->flags) 497 + return processed; 498 + 499 + /* check whether one of B,C,D flags were changed */ 500 + if ((oldflags ^ priv->flags) & 501 + (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D)) 502 + /* set display mode */ 503 + lcd->ops->write_cmd(lcd, 504 + LCD_CMD_DISPLAY_CTRL | 505 + ((priv->flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) | 506 + ((priv->flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) | 507 + ((priv->flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)); 508 + /* check whether one of F,N flags was changed */ 509 + else if ((oldflags ^ priv->flags) & (LCD_FLAG_F | LCD_FLAG_N)) 510 + lcd->ops->write_cmd(lcd, 511 + LCD_CMD_FUNCTION_SET | 512 + ((lcd->ifwidth == 8) ? LCD_CMD_DATA_LEN_8BITS : 0) | 513 + ((priv->flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) | 514 + ((priv->flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)); 515 + /* check whether L flag was changed */ 516 + else if ((oldflags ^ priv->flags) & LCD_FLAG_L) 517 + charlcd_backlight(lcd, !!(priv->flags & LCD_FLAG_L)); 518 + 519 + return processed; 520 + } 521 + 522 + static void charlcd_write_char(struct charlcd *lcd, char c) 523 + { 524 + struct charlcd_priv *priv = to_priv(lcd); 525 + 526 + /* first, we'll test if we're in escape mode */ 527 + if ((c != '\n') && priv->esc_seq.len >= 0) { 528 + /* yes, let's add this char to the buffer */ 529 + priv->esc_seq.buf[priv->esc_seq.len++] = c; 530 + priv->esc_seq.buf[priv->esc_seq.len] = 0; 531 + } else { 532 + /* aborts any previous escape sequence */ 533 + priv->esc_seq.len = -1; 534 + 535 + switch (c) { 536 + case LCD_ESCAPE_CHAR: 537 + /* start of an escape sequence */ 538 + priv->esc_seq.len = 0; 539 + priv->esc_seq.buf[priv->esc_seq.len] = 0; 540 + break; 541 + case '\b': 542 + /* go back one char and clear it */ 543 + if (priv->addr.x > 0) { 544 + /* 545 + * check if we're not at the 546 + * end of the line 547 + */ 548 + if (priv->addr.x < lcd->bwidth) 549 + /* back one char */ 550 + lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); 551 + priv->addr.x--; 552 + } 553 + /* replace with a space */ 554 + lcd->ops->write_data(lcd, ' '); 555 + /* back one char again */ 556 + lcd->ops->write_cmd(lcd, LCD_CMD_SHIFT); 557 + break; 558 + case '\014': 559 + /* quickly clear the display */ 560 + charlcd_clear_fast(lcd); 561 + break; 562 + case '\n': 563 + /* 564 + * flush the remainder of the current line and 565 + * go to the beginning of the next line 566 + */ 567 + for (; priv->addr.x < lcd->bwidth; priv->addr.x++) 568 + lcd->ops->write_data(lcd, ' '); 569 + priv->addr.x = 0; 570 + priv->addr.y = (priv->addr.y + 1) % lcd->height; 571 + charlcd_gotoxy(lcd); 572 + break; 573 + case '\r': 574 + /* go to the beginning of the same line */ 575 + priv->addr.x = 0; 576 + charlcd_gotoxy(lcd); 577 + break; 578 + case '\t': 579 + /* print a space instead of the tab */ 580 + charlcd_print(lcd, ' '); 581 + break; 582 + default: 583 + /* simply print this char */ 584 + charlcd_print(lcd, c); 585 + break; 586 + } 587 + } 588 + 589 + /* 590 + * now we'll see if we're in an escape mode and if the current 591 + * escape sequence can be understood. 592 + */ 593 + if (priv->esc_seq.len >= 2) { 594 + int processed = 0; 595 + 596 + if (!strcmp(priv->esc_seq.buf, "[2J")) { 597 + /* clear the display */ 598 + charlcd_clear_fast(lcd); 599 + processed = 1; 600 + } else if (!strcmp(priv->esc_seq.buf, "[H")) { 601 + /* cursor to home */ 602 + charlcd_home(lcd); 603 + processed = 1; 604 + } 605 + /* codes starting with ^[[L */ 606 + else if ((priv->esc_seq.len >= 3) && 607 + (priv->esc_seq.buf[0] == '[') && 608 + (priv->esc_seq.buf[1] == 'L')) { 609 + processed = handle_lcd_special_code(lcd); 610 + } 611 + 612 + /* LCD special escape codes */ 613 + /* 614 + * flush the escape sequence if it's been processed 615 + * or if it is getting too long. 616 + */ 617 + if (processed || (priv->esc_seq.len >= LCD_ESCAPE_LEN)) 618 + priv->esc_seq.len = -1; 619 + } /* escape codes */ 620 + } 621 + 622 + static struct charlcd *the_charlcd; 623 + 624 + static ssize_t charlcd_write(struct file *file, const char __user *buf, 625 + size_t count, loff_t *ppos) 626 + { 627 + const char __user *tmp = buf; 628 + char c; 629 + 630 + for (; count-- > 0; (*ppos)++, tmp++) { 631 + if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) 632 + /* 633 + * let's be a little nice with other processes 634 + * that need some CPU 635 + */ 636 + schedule(); 637 + 638 + if (get_user(c, tmp)) 639 + return -EFAULT; 640 + 641 + charlcd_write_char(the_charlcd, c); 642 + } 643 + 644 + return tmp - buf; 645 + } 646 + 647 + static int charlcd_open(struct inode *inode, struct file *file) 648 + { 649 + struct charlcd_priv *priv = to_priv(the_charlcd); 650 + 651 + if (!atomic_dec_and_test(&charlcd_available)) 652 + return -EBUSY; /* open only once at a time */ 653 + 654 + if (file->f_mode & FMODE_READ) /* device is write-only */ 655 + return -EPERM; 656 + 657 + if (priv->must_clear) { 658 + charlcd_clear_display(&priv->lcd); 659 + priv->must_clear = false; 660 + } 661 + return nonseekable_open(inode, file); 662 + } 663 + 664 + static int charlcd_release(struct inode *inode, struct file *file) 665 + { 666 + atomic_inc(&charlcd_available); 667 + return 0; 668 + } 669 + 670 + static const struct file_operations charlcd_fops = { 671 + .write = charlcd_write, 672 + .open = charlcd_open, 673 + .release = charlcd_release, 674 + .llseek = no_llseek, 675 + }; 676 + 677 + static struct miscdevice charlcd_dev = { 678 + .minor = LCD_MINOR, 679 + .name = "lcd", 680 + .fops = &charlcd_fops, 681 + }; 682 + 683 + static void charlcd_puts(struct charlcd *lcd, const char *s) 684 + { 685 + const char *tmp = s; 686 + int count = strlen(s); 687 + 688 + for (; count-- > 0; tmp++) { 689 + if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) 690 + /* 691 + * let's be a little nice with other processes 692 + * that need some CPU 693 + */ 694 + schedule(); 695 + 696 + charlcd_write_char(lcd, *tmp); 697 + } 698 + } 699 + 700 + /* initialize the LCD driver */ 701 + static int charlcd_init(struct charlcd *lcd) 702 + { 703 + struct charlcd_priv *priv = to_priv(lcd); 704 + int ret; 705 + 706 + if (lcd->ops->backlight) { 707 + mutex_init(&priv->bl_tempo_lock); 708 + INIT_DELAYED_WORK(&priv->bl_work, charlcd_bl_off); 709 + } 710 + 711 + /* 712 + * before this line, we must NOT send anything to the display. 713 + * Since charlcd_init_display() needs to write data, we have to 714 + * enable mark the LCD initialized just before. 715 + */ 716 + ret = charlcd_init_display(lcd); 717 + if (ret) 718 + return ret; 719 + 720 + /* display a short message */ 721 + #ifdef CONFIG_PANEL_CHANGE_MESSAGE 722 + #ifdef CONFIG_PANEL_BOOT_MESSAGE 723 + charlcd_puts(lcd, "\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE); 724 + #endif 725 + #else 726 + charlcd_puts(lcd, "\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\n"); 727 + #endif 728 + /* clear the display on the next device opening */ 729 + priv->must_clear = true; 730 + charlcd_home(lcd); 731 + return 0; 732 + } 733 + 734 + struct charlcd *charlcd_alloc(unsigned int drvdata_size) 735 + { 736 + struct charlcd_priv *priv; 737 + struct charlcd *lcd; 738 + 739 + priv = kzalloc(sizeof(*priv) + drvdata_size, GFP_KERNEL); 740 + if (!priv) 741 + return NULL; 742 + 743 + priv->esc_seq.len = -1; 744 + 745 + lcd = &priv->lcd; 746 + lcd->ifwidth = 8; 747 + lcd->bwidth = DEFAULT_LCD_BWIDTH; 748 + lcd->hwidth = DEFAULT_LCD_HWIDTH; 749 + lcd->drvdata = priv->drvdata; 750 + 751 + return lcd; 752 + } 753 + EXPORT_SYMBOL_GPL(charlcd_alloc); 754 + 755 + static int panel_notify_sys(struct notifier_block *this, unsigned long code, 756 + void *unused) 757 + { 758 + struct charlcd *lcd = the_charlcd; 759 + 760 + switch (code) { 761 + case SYS_DOWN: 762 + charlcd_puts(lcd, 763 + "\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+"); 764 + break; 765 + case SYS_HALT: 766 + charlcd_puts(lcd, "\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); 767 + break; 768 + case SYS_POWER_OFF: 769 + charlcd_puts(lcd, "\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); 770 + break; 771 + default: 772 + break; 773 + } 774 + return NOTIFY_DONE; 775 + } 776 + 777 + static struct notifier_block panel_notifier = { 778 + panel_notify_sys, 779 + NULL, 780 + 0 781 + }; 782 + 783 + int charlcd_register(struct charlcd *lcd) 784 + { 785 + int ret; 786 + 787 + ret = charlcd_init(lcd); 788 + if (ret) 789 + return ret; 790 + 791 + ret = misc_register(&charlcd_dev); 792 + if (ret) 793 + return ret; 794 + 795 + the_charlcd = lcd; 796 + register_reboot_notifier(&panel_notifier); 797 + return 0; 798 + } 799 + EXPORT_SYMBOL_GPL(charlcd_register); 800 + 801 + int charlcd_unregister(struct charlcd *lcd) 802 + { 803 + struct charlcd_priv *priv = to_priv(lcd); 804 + 805 + unregister_reboot_notifier(&panel_notifier); 806 + charlcd_puts(lcd, "\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); 807 + misc_deregister(&charlcd_dev); 808 + the_charlcd = NULL; 809 + if (lcd->ops->backlight) { 810 + cancel_delayed_work_sync(&priv->bl_work); 811 + priv->lcd.ops->backlight(&priv->lcd, 0); 812 + } 813 + 814 + return 0; 815 + } 816 + EXPORT_SYMBOL_GPL(charlcd_unregister); 817 + 818 + MODULE_LICENSE("GPL");
+326
drivers/auxdisplay/hd44780.c
··· 1 + /* 2 + * HD44780 Character LCD driver for Linux 3 + * 4 + * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> 5 + * Copyright (C) 2016-2017 Glider bvba 6 + * 7 + * This program is free software; you can redistribute it and/or 8 + * modify it under the terms of the GNU General Public License 9 + * as published by the Free Software Foundation; either version 10 + * 2 of the License, or (at your option) any later version. 11 + */ 12 + 13 + #include <linux/delay.h> 14 + #include <linux/gpio/consumer.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/property.h> 18 + #include <linux/slab.h> 19 + 20 + #include <misc/charlcd.h> 21 + 22 + 23 + enum hd44780_pin { 24 + /* Order does matter due to writing to GPIO array subsets! */ 25 + PIN_DATA0, /* Optional */ 26 + PIN_DATA1, /* Optional */ 27 + PIN_DATA2, /* Optional */ 28 + PIN_DATA3, /* Optional */ 29 + PIN_DATA4, 30 + PIN_DATA5, 31 + PIN_DATA6, 32 + PIN_DATA7, 33 + PIN_CTRL_RS, 34 + PIN_CTRL_RW, /* Optional */ 35 + PIN_CTRL_E, 36 + PIN_CTRL_BL, /* Optional */ 37 + PIN_NUM 38 + }; 39 + 40 + struct hd44780 { 41 + struct gpio_desc *pins[PIN_NUM]; 42 + }; 43 + 44 + static void hd44780_backlight(struct charlcd *lcd, int on) 45 + { 46 + struct hd44780 *hd = lcd->drvdata; 47 + 48 + if (hd->pins[PIN_CTRL_BL]) 49 + gpiod_set_value_cansleep(hd->pins[PIN_CTRL_BL], on); 50 + } 51 + 52 + static void hd44780_strobe_gpio(struct hd44780 *hd) 53 + { 54 + /* Maintain the data during 20 us before the strobe */ 55 + udelay(20); 56 + 57 + gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 1); 58 + 59 + /* Maintain the strobe during 40 us */ 60 + udelay(40); 61 + 62 + gpiod_set_value_cansleep(hd->pins[PIN_CTRL_E], 0); 63 + } 64 + 65 + /* write to an LCD panel register in 8 bit GPIO mode */ 66 + static void hd44780_write_gpio8(struct hd44780 *hd, u8 val, unsigned int rs) 67 + { 68 + int values[10]; /* for DATA[0-7], RS, RW */ 69 + unsigned int i, n; 70 + 71 + for (i = 0; i < 8; i++) 72 + values[PIN_DATA0 + i] = !!(val & BIT(i)); 73 + values[PIN_CTRL_RS] = rs; 74 + n = 9; 75 + if (hd->pins[PIN_CTRL_RW]) { 76 + values[PIN_CTRL_RW] = 0; 77 + n++; 78 + } 79 + 80 + /* Present the data to the port */ 81 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA0], values); 82 + 83 + hd44780_strobe_gpio(hd); 84 + } 85 + 86 + /* write to an LCD panel register in 4 bit GPIO mode */ 87 + static void hd44780_write_gpio4(struct hd44780 *hd, u8 val, unsigned int rs) 88 + { 89 + int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */ 90 + unsigned int i, n; 91 + 92 + /* High nibble + RS, RW */ 93 + for (i = 4; i < 8; i++) 94 + values[PIN_DATA0 + i] = !!(val & BIT(i)); 95 + values[PIN_CTRL_RS] = rs; 96 + n = 5; 97 + if (hd->pins[PIN_CTRL_RW]) { 98 + values[PIN_CTRL_RW] = 0; 99 + n++; 100 + } 101 + 102 + /* Present the data to the port */ 103 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 104 + &values[PIN_DATA4]); 105 + 106 + hd44780_strobe_gpio(hd); 107 + 108 + /* Low nibble */ 109 + for (i = 0; i < 4; i++) 110 + values[PIN_DATA4 + i] = !!(val & BIT(i)); 111 + 112 + /* Present the data to the port */ 113 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 114 + &values[PIN_DATA4]); 115 + 116 + hd44780_strobe_gpio(hd); 117 + } 118 + 119 + /* Send a command to the LCD panel in 8 bit GPIO mode */ 120 + static void hd44780_write_cmd_gpio8(struct charlcd *lcd, int cmd) 121 + { 122 + struct hd44780 *hd = lcd->drvdata; 123 + 124 + hd44780_write_gpio8(hd, cmd, 0); 125 + 126 + /* The shortest command takes at least 120 us */ 127 + udelay(120); 128 + } 129 + 130 + /* Send data to the LCD panel in 8 bit GPIO mode */ 131 + static void hd44780_write_data_gpio8(struct charlcd *lcd, int data) 132 + { 133 + struct hd44780 *hd = lcd->drvdata; 134 + 135 + hd44780_write_gpio8(hd, data, 1); 136 + 137 + /* The shortest data takes at least 45 us */ 138 + udelay(45); 139 + } 140 + 141 + static const struct charlcd_ops hd44780_ops_gpio8 = { 142 + .write_cmd = hd44780_write_cmd_gpio8, 143 + .write_data = hd44780_write_data_gpio8, 144 + .backlight = hd44780_backlight, 145 + }; 146 + 147 + /* Send a command to the LCD panel in 4 bit GPIO mode */ 148 + static void hd44780_write_cmd_gpio4(struct charlcd *lcd, int cmd) 149 + { 150 + struct hd44780 *hd = lcd->drvdata; 151 + 152 + hd44780_write_gpio4(hd, cmd, 0); 153 + 154 + /* The shortest command takes at least 120 us */ 155 + udelay(120); 156 + } 157 + 158 + /* Send 4-bits of a command to the LCD panel in raw 4 bit GPIO mode */ 159 + static void hd44780_write_cmd_raw_gpio4(struct charlcd *lcd, int cmd) 160 + { 161 + int values[10]; /* for DATA[0-7], RS, RW, but DATA[0-3] is unused */ 162 + struct hd44780 *hd = lcd->drvdata; 163 + unsigned int i, n; 164 + 165 + /* Command nibble + RS, RW */ 166 + for (i = 0; i < 4; i++) 167 + values[PIN_DATA4 + i] = !!(cmd & BIT(i)); 168 + values[PIN_CTRL_RS] = 0; 169 + n = 5; 170 + if (hd->pins[PIN_CTRL_RW]) { 171 + values[PIN_CTRL_RW] = 0; 172 + n++; 173 + } 174 + 175 + /* Present the data to the port */ 176 + gpiod_set_array_value_cansleep(n, &hd->pins[PIN_DATA4], 177 + &values[PIN_DATA4]); 178 + 179 + hd44780_strobe_gpio(hd); 180 + } 181 + 182 + /* Send data to the LCD panel in 4 bit GPIO mode */ 183 + static void hd44780_write_data_gpio4(struct charlcd *lcd, int data) 184 + { 185 + struct hd44780 *hd = lcd->drvdata; 186 + 187 + hd44780_write_gpio4(hd, data, 1); 188 + 189 + /* The shortest data takes at least 45 us */ 190 + udelay(45); 191 + } 192 + 193 + static const struct charlcd_ops hd44780_ops_gpio4 = { 194 + .write_cmd = hd44780_write_cmd_gpio4, 195 + .write_cmd_raw4 = hd44780_write_cmd_raw_gpio4, 196 + .write_data = hd44780_write_data_gpio4, 197 + .backlight = hd44780_backlight, 198 + }; 199 + 200 + static int hd44780_probe(struct platform_device *pdev) 201 + { 202 + struct device *dev = &pdev->dev; 203 + unsigned int i, base; 204 + struct charlcd *lcd; 205 + struct hd44780 *hd; 206 + int ifwidth, ret; 207 + 208 + /* Required pins */ 209 + ifwidth = gpiod_count(dev, "data"); 210 + if (ifwidth < 0) 211 + return ifwidth; 212 + 213 + switch (ifwidth) { 214 + case 4: 215 + base = PIN_DATA4; 216 + break; 217 + case 8: 218 + base = PIN_DATA0; 219 + break; 220 + default: 221 + return -EINVAL; 222 + } 223 + 224 + lcd = charlcd_alloc(sizeof(struct hd44780)); 225 + if (!lcd) 226 + return -ENOMEM; 227 + 228 + hd = lcd->drvdata; 229 + 230 + for (i = 0; i < ifwidth; i++) { 231 + hd->pins[base + i] = devm_gpiod_get_index(dev, "data", i, 232 + GPIOD_OUT_LOW); 233 + if (IS_ERR(hd->pins[base + i])) { 234 + ret = PTR_ERR(hd->pins[base + i]); 235 + goto fail; 236 + } 237 + } 238 + 239 + hd->pins[PIN_CTRL_E] = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); 240 + if (IS_ERR(hd->pins[PIN_CTRL_E])) { 241 + ret = PTR_ERR(hd->pins[PIN_CTRL_E]); 242 + goto fail; 243 + } 244 + 245 + hd->pins[PIN_CTRL_RS] = devm_gpiod_get(dev, "rs", GPIOD_OUT_HIGH); 246 + if (IS_ERR(hd->pins[PIN_CTRL_RS])) { 247 + ret = PTR_ERR(hd->pins[PIN_CTRL_RS]); 248 + goto fail; 249 + } 250 + 251 + /* Optional pins */ 252 + hd->pins[PIN_CTRL_RW] = devm_gpiod_get_optional(dev, "rw", 253 + GPIOD_OUT_LOW); 254 + if (IS_ERR(hd->pins[PIN_CTRL_RW])) { 255 + ret = PTR_ERR(hd->pins[PIN_CTRL_RW]); 256 + goto fail; 257 + } 258 + 259 + hd->pins[PIN_CTRL_BL] = devm_gpiod_get_optional(dev, "backlight", 260 + GPIOD_OUT_LOW); 261 + if (IS_ERR(hd->pins[PIN_CTRL_BL])) { 262 + ret = PTR_ERR(hd->pins[PIN_CTRL_BL]); 263 + goto fail; 264 + } 265 + 266 + /* Required properties */ 267 + ret = device_property_read_u32(dev, "display-height-chars", 268 + &lcd->height); 269 + if (ret) 270 + goto fail; 271 + ret = device_property_read_u32(dev, "display-width-chars", &lcd->width); 272 + if (ret) 273 + goto fail; 274 + 275 + /* 276 + * On displays with more than two rows, the internal buffer width is 277 + * usually equal to the display width 278 + */ 279 + if (lcd->height > 2) 280 + lcd->bwidth = lcd->width; 281 + 282 + /* Optional properties */ 283 + device_property_read_u32(dev, "internal-buffer-width", &lcd->bwidth); 284 + 285 + lcd->ifwidth = ifwidth; 286 + lcd->ops = ifwidth == 8 ? &hd44780_ops_gpio8 : &hd44780_ops_gpio4; 287 + 288 + ret = charlcd_register(lcd); 289 + if (ret) 290 + goto fail; 291 + 292 + platform_set_drvdata(pdev, lcd); 293 + return 0; 294 + 295 + fail: 296 + kfree(lcd); 297 + return ret; 298 + } 299 + 300 + static int hd44780_remove(struct platform_device *pdev) 301 + { 302 + struct charlcd *lcd = platform_get_drvdata(pdev); 303 + 304 + charlcd_unregister(lcd); 305 + return 0; 306 + } 307 + 308 + static const struct of_device_id hd44780_of_match[] = { 309 + { .compatible = "hit,hd44780" }, 310 + { /* sentinel */ } 311 + }; 312 + MODULE_DEVICE_TABLE(of, hd44780_of_match); 313 + 314 + static struct platform_driver hd44780_driver = { 315 + .probe = hd44780_probe, 316 + .remove = hd44780_remove, 317 + .driver = { 318 + .name = "hd44780", 319 + .of_match_table = hd44780_of_match, 320 + }, 321 + }; 322 + 323 + module_platform_driver(hd44780_driver); 324 + MODULE_DESCRIPTION("HD44780 Character LCD driver"); 325 + MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 326 + MODULE_LICENSE("GPL");
+15 -5
drivers/auxdisplay/ht16k33.c
··· 254 254 { 255 255 const unsigned short *keycodes = keypad->dev->keycode; 256 256 u16 new_state[HT16K33_MATRIX_KEYPAD_MAX_COLS]; 257 - u8 data[HT16K33_MATRIX_KEYPAD_MAX_COLS * 2]; 257 + __le16 data[HT16K33_MATRIX_KEYPAD_MAX_COLS]; 258 258 unsigned long bits_changed; 259 259 int row, col, code; 260 + int rc; 260 261 bool pressed = false; 261 262 262 - if (i2c_smbus_read_i2c_block_data(keypad->client, 0x40, 6, data) != 6) { 263 - dev_err(&keypad->client->dev, "Failed to read key data\n"); 263 + rc = i2c_smbus_read_i2c_block_data(keypad->client, 0x40, 264 + sizeof(data), (u8 *)data); 265 + if (rc != sizeof(data)) { 266 + dev_err(&keypad->client->dev, 267 + "Failed to read key data, rc=%d\n", rc); 264 268 return false; 265 269 } 266 270 267 271 for (col = 0; col < keypad->cols; col++) { 268 - new_state[col] = (data[col * 2 + 1] << 8) | data[col * 2]; 272 + new_state[col] = le16_to_cpu(data[col]); 269 273 if (new_state[col]) 270 274 pressed = true; 271 275 bits_changed = keypad->last_key_state[col] ^ new_state[col]; ··· 282 278 } 283 279 } 284 280 input_sync(keypad->dev); 285 - memcpy(keypad->last_key_state, new_state, sizeof(new_state)); 281 + memcpy(keypad->last_key_state, new_state, sizeof(u16) * keypad->cols); 286 282 287 283 return pressed; 288 284 } ··· 357 353 err = matrix_keypad_parse_of_params(&client->dev, &rows, &cols); 358 354 if (err) 359 355 return err; 356 + if (rows > HT16K33_MATRIX_KEYPAD_MAX_ROWS || 357 + cols > HT16K33_MATRIX_KEYPAD_MAX_COLS) { 358 + dev_err(&client->dev, "%u rows or %u cols out of range in DT\n", 359 + rows, cols); 360 + return -ERANGE; 361 + } 360 362 361 363 keypad->rows = rows; 362 364 keypad->cols = cols;
+1
drivers/auxdisplay/img-ascii-lcd.c
··· 220 220 { .compatible = "mti,sead3-lcd", .data = &sead3_config }, 221 221 { /* sentinel */ } 222 222 }; 223 + MODULE_DEVICE_TABLE(of, img_ascii_lcd_matches); 223 224 224 225 /** 225 226 * img_ascii_lcd_scroll() - scroll the display by a character
+1 -1
drivers/char/hangcheck-timer.c
··· 32 32 * timer and 180 seconds for the margin of error. IOW, a timer is set 33 33 * for 60 seconds. When the timer fires, the callback checks the 34 34 * actual duration that the timer waited. If the duration exceeds the 35 - * alloted time and margin (here 60 + 180, or 240 seconds), the machine 35 + * allotted time and margin (here 60 + 180, or 240 seconds), the machine 36 36 * is restarted. A healthy machine will have the duration match the 37 37 * expected timeout very closely. 38 38 */
+1 -1
drivers/char/hpet.c
··· 575 575 } 576 576 577 577 static int 578 - hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, 578 + hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, 579 579 struct hpet_info *info) 580 580 { 581 581 struct hpet_timer __iomem *timer;
+6 -5
drivers/char/misc.c
··· 109 109 }; 110 110 #endif 111 111 112 - static int misc_open(struct inode * inode, struct file * file) 112 + static int misc_open(struct inode *inode, struct file *file) 113 113 { 114 114 int minor = iminor(inode); 115 115 struct miscdevice *c; ··· 150 150 err = 0; 151 151 replace_fops(file, new_fops); 152 152 if (file->f_op->open) 153 - err = file->f_op->open(inode,file); 153 + err = file->f_op->open(inode, file); 154 154 fail: 155 155 mutex_unlock(&misc_mtx); 156 156 return err; ··· 182 182 * failure. 183 183 */ 184 184 185 - int misc_register(struct miscdevice * misc) 185 + int misc_register(struct miscdevice *misc) 186 186 { 187 187 dev_t dev; 188 188 int err = 0; ··· 194 194 195 195 if (is_dynamic) { 196 196 int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS); 197 + 197 198 if (i >= DYNAMIC_MINORS) { 198 199 err = -EBUSY; 199 200 goto out; ··· 288 287 goto fail_remove; 289 288 290 289 err = -EIO; 291 - if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) 290 + if (register_chrdev(MISC_MAJOR, "misc", &misc_fops)) 292 291 goto fail_printk; 293 292 misc_class->devnode = misc_devnode; 294 293 return 0; 295 294 296 295 fail_printk: 297 - printk("unable to get major %d for misc devices\n", MISC_MAJOR); 296 + pr_err("unable to get major %d for misc devices\n", MISC_MAJOR); 298 297 class_destroy(misc_class); 299 298 fail_remove: 300 299 if (ret)
+5 -4
drivers/char/mspec.c
··· 43 43 #include <linux/string.h> 44 44 #include <linux/slab.h> 45 45 #include <linux/numa.h> 46 + #include <linux/refcount.h> 46 47 #include <asm/page.h> 47 48 #include <asm/pgtable.h> 48 49 #include <linux/atomic.h> ··· 90 89 * protect in fork case where multiple tasks share the vma_data. 91 90 */ 92 91 struct vma_data { 93 - atomic_t refcnt; /* Number of vmas sharing the data. */ 92 + refcount_t refcnt; /* Number of vmas sharing the data. */ 94 93 spinlock_t lock; /* Serialize access to this structure. */ 95 94 int count; /* Number of pages allocated. */ 96 95 enum mspec_page_type type; /* Type of pages allocated. */ ··· 145 144 struct vma_data *vdata; 146 145 147 146 vdata = vma->vm_private_data; 148 - atomic_inc(&vdata->refcnt); 147 + refcount_inc(&vdata->refcnt); 149 148 } 150 149 151 150 /* ··· 163 162 164 163 vdata = vma->vm_private_data; 165 164 166 - if (!atomic_dec_and_test(&vdata->refcnt)) 165 + if (!refcount_dec_and_test(&vdata->refcnt)) 167 166 return; 168 167 169 168 last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT; ··· 275 274 vdata->vm_end = vma->vm_end; 276 275 vdata->type = type; 277 276 spin_lock_init(&vdata->lock); 278 - atomic_set(&vdata->refcnt, 1); 277 + refcount_set(&vdata->refcnt, 1); 279 278 vma->vm_private_data = vdata; 280 279 281 280 vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
+14 -40
drivers/char/tpm/tpm-chip.c
··· 218 218 cdev_init(&chip->cdevs, &tpmrm_fops); 219 219 chip->cdev.owner = THIS_MODULE; 220 220 chip->cdevs.owner = THIS_MODULE; 221 - chip->cdev.kobj.parent = &chip->dev.kobj; 222 - chip->cdevs.kobj.parent = &chip->devs.kobj; 223 221 224 222 chip->work_space.context_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); 225 223 if (!chip->work_space.context_buf) { ··· 273 275 { 274 276 int rc; 275 277 276 - rc = cdev_add(&chip->cdev, chip->dev.devt, 1); 278 + rc = cdev_device_add(&chip->cdev, &chip->dev); 277 279 if (rc) { 278 280 dev_err(&chip->dev, 279 - "unable to cdev_add() %s, major %d, minor %d, err=%d\n", 281 + "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n", 280 282 dev_name(&chip->dev), MAJOR(chip->dev.devt), 281 283 MINOR(chip->dev.devt), rc); 282 284 return rc; 283 285 } 284 286 285 - rc = device_add(&chip->dev); 286 - if (rc) { 287 - dev_err(&chip->dev, 288 - "unable to device_register() %s, major %d, minor %d, err=%d\n", 289 - dev_name(&chip->dev), MAJOR(chip->dev.devt), 290 - MINOR(chip->dev.devt), rc); 291 - 292 - cdev_del(&chip->cdev); 293 - return rc; 294 - } 295 - 296 - if (chip->flags & TPM_CHIP_FLAG_TPM2) 297 - rc = cdev_add(&chip->cdevs, chip->devs.devt, 1); 298 - if (rc) { 299 - dev_err(&chip->dev, 300 - "unable to cdev_add() %s, major %d, minor %d, err=%d\n", 301 - dev_name(&chip->devs), MAJOR(chip->devs.devt), 302 - MINOR(chip->devs.devt), rc); 303 - return rc; 304 - } 305 - 306 - if (chip->flags & TPM_CHIP_FLAG_TPM2) 307 - rc = device_add(&chip->devs); 308 - if (rc) { 309 - dev_err(&chip->dev, 310 - "unable to device_register() %s, major %d, minor %d, err=%d\n", 311 - dev_name(&chip->devs), MAJOR(chip->devs.devt), 312 - MINOR(chip->devs.devt), rc); 313 - cdev_del(&chip->cdevs); 314 - return rc; 287 + if (chip->flags & TPM_CHIP_FLAG_TPM2) { 288 + rc = cdev_device_add(&chip->cdevs, &chip->devs); 289 + if (rc) { 290 + dev_err(&chip->devs, 291 + "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n", 292 + dev_name(&chip->devs), MAJOR(chip->devs.devt), 293 + MINOR(chip->devs.devt), rc); 294 + return rc; 295 + } 315 296 } 316 297 317 298 /* Make the chip available. */ ··· 303 326 304 327 static void tpm_del_char_device(struct tpm_chip *chip) 305 328 { 306 - cdev_del(&chip->cdev); 307 - device_del(&chip->dev); 329 + cdev_device_del(&chip->cdev, &chip->dev); 308 330 309 331 /* Make the chip unavailable. */ 310 332 mutex_lock(&idr_lock); ··· 425 449 { 426 450 tpm_del_legacy_sysfs(chip); 427 451 tpm_bios_log_teardown(chip); 428 - if (chip->flags & TPM_CHIP_FLAG_TPM2) { 429 - cdev_del(&chip->cdevs); 430 - device_del(&chip->devs); 431 - } 452 + if (chip->flags & TPM_CHIP_FLAG_TPM2) 453 + cdev_device_del(&chip->cdevs, &chip->devs); 432 454 tpm_del_char_device(chip); 433 455 } 434 456 EXPORT_SYMBOL_GPL(tpm_chip_unregister);
+1 -1
drivers/char/virtio_console.c
··· 2304 2304 2305 2305 pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL); 2306 2306 if (!pdrvdata.debugfs_dir) 2307 - pr_warning("Error creating debugfs dir for virtio-ports\n"); 2307 + pr_warn("Error creating debugfs dir for virtio-ports\n"); 2308 2308 INIT_LIST_HEAD(&pdrvdata.consoles); 2309 2309 INIT_LIST_HEAD(&pdrvdata.portdevs); 2310 2310
+16 -17
drivers/dax/dax.c
··· 703 703 kfree(dax_dev); 704 704 } 705 705 706 - static void unregister_dax_dev(void *dev) 706 + static void kill_dax_dev(struct dax_dev *dax_dev) 707 707 { 708 - struct dax_dev *dax_dev = to_dax_dev(dev); 709 - struct cdev *cdev = &dax_dev->cdev; 710 - 711 - dev_dbg(dev, "%s\n", __func__); 712 - 713 708 /* 714 709 * Note, rcu is not protecting the liveness of dax_dev, rcu is 715 710 * ensuring that any fault handlers that might have seen ··· 715 720 dax_dev->alive = false; 716 721 synchronize_srcu(&dax_srcu); 717 722 unmap_mapping_range(dax_dev->inode->i_mapping, 0, 0, 1); 718 - cdev_del(cdev); 719 - device_unregister(dev); 723 + } 724 + 725 + static void unregister_dax_dev(void *dev) 726 + { 727 + struct dax_dev *dax_dev = to_dax_dev(dev); 728 + 729 + dev_dbg(dev, "%s\n", __func__); 730 + 731 + kill_dax_dev(dax_dev); 732 + cdev_device_del(&dax_dev->cdev, dev); 733 + put_device(dev); 720 734 } 721 735 722 736 struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region, ··· 776 772 goto err_inode; 777 773 } 778 774 779 - /* device_initialize() so cdev can reference kobj parent */ 775 + /* from here on we're committed to teardown via dax_dev_release() */ 780 776 device_initialize(dev); 781 777 782 778 cdev = &dax_dev->cdev; 783 779 cdev_init(cdev, &dax_fops); 784 780 cdev->owner = parent->driver->owner; 785 - cdev->kobj.parent = &dev->kobj; 786 - rc = cdev_add(&dax_dev->cdev, dev_t, 1); 787 - if (rc) 788 - goto err_cdev; 789 781 790 - /* from here on we're committed to teardown via dax_dev_release() */ 791 782 dax_dev->num_resources = count; 792 783 dax_dev->alive = true; 793 784 dax_dev->region = dax_region; ··· 794 795 dev->groups = dax_attribute_groups; 795 796 dev->release = dax_dev_release; 796 797 dev_set_name(dev, "dax%d.%d", dax_region->id, dax_dev->id); 797 - rc = device_add(dev); 798 + 799 + rc = cdev_device_add(cdev, dev); 798 800 if (rc) { 801 + kill_dax_dev(dax_dev); 799 802 put_device(dev); 800 803 return ERR_PTR(rc); 801 804 } ··· 808 807 809 808 return dax_dev; 810 809 811 - err_cdev: 812 - iput(dax_dev->inode); 813 810 err_inode: 814 811 ida_simple_remove(&dax_minor_ida, minor); 815 812 err_minor:
+7
drivers/extcon/Kconfig
··· 52 52 This ACPI device is typically found on Intel Baytrail or Cherrytrail 53 53 based tablets, or other Baytrail / Cherrytrail devices. 54 54 55 + config EXTCON_INTEL_CHT_WC 56 + tristate "Intel Cherrytrail Whiskey Cove PMIC extcon driver" 57 + depends on INTEL_SOC_PMIC_CHTWC 58 + help 59 + Say Y here to enable extcon support for charger detection / control 60 + on the Intel Cherrytrail Whiskey Cove PMIC. 61 + 55 62 config EXTCON_MAX14577 56 63 tristate "Maxim MAX14577/77836 EXTCON Support" 57 64 depends on MFD_MAX14577
+1
drivers/extcon/Makefile
··· 9 9 obj-$(CONFIG_EXTCON_AXP288) += extcon-axp288.o 10 10 obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o 11 11 obj-$(CONFIG_EXTCON_INTEL_INT3496) += extcon-intel-int3496.o 12 + obj-$(CONFIG_EXTCON_INTEL_CHT_WC) += extcon-intel-cht-wc.o 12 13 obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o 13 14 obj-$(CONFIG_EXTCON_MAX3355) += extcon-max3355.o 14 15 obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o
+46
drivers/extcon/extcon-arizona.c
··· 51 51 #define HPDET_DEBOUNCE 500 52 52 #define DEFAULT_MICD_TIMEOUT 2000 53 53 54 + #define ARIZONA_HPDET_WAIT_COUNT 15 55 + #define ARIZONA_HPDET_WAIT_DELAY_MS 20 56 + 54 57 #define QUICK_HEADPHONE_MAX_OHM 3 55 58 #define MICROPHONE_MIN_OHM 1257 56 59 #define MICROPHONE_MAX_OHM 30000 ··· 1052 1049 mutex_unlock(&info->lock); 1053 1050 } 1054 1051 1052 + static int arizona_hpdet_wait(struct arizona_extcon_info *info) 1053 + { 1054 + struct arizona *arizona = info->arizona; 1055 + unsigned int val; 1056 + int i, ret; 1057 + 1058 + for (i = 0; i < ARIZONA_HPDET_WAIT_COUNT; i++) { 1059 + ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, 1060 + &val); 1061 + if (ret) { 1062 + dev_err(arizona->dev, 1063 + "Failed to read HPDET state: %d\n", ret); 1064 + return ret; 1065 + } 1066 + 1067 + switch (info->hpdet_ip_version) { 1068 + case 0: 1069 + if (val & ARIZONA_HP_DONE) 1070 + return 0; 1071 + break; 1072 + default: 1073 + if (val & ARIZONA_HP_DONE_B) 1074 + return 0; 1075 + break; 1076 + } 1077 + 1078 + msleep(ARIZONA_HPDET_WAIT_DELAY_MS); 1079 + } 1080 + 1081 + dev_warn(arizona->dev, "HPDET did not appear to complete\n"); 1082 + 1083 + return -ETIMEDOUT; 1084 + } 1085 + 1055 1086 static irqreturn_t arizona_jackdet(int irq, void *data) 1056 1087 { 1057 1088 struct arizona_extcon_info *info = data; ··· 1191 1154 dev_err(arizona->dev, 1192 1155 "Removal report failed: %d\n", ret); 1193 1156 } 1157 + 1158 + /* 1159 + * If the jack was removed during a headphone detection we 1160 + * need to wait for the headphone detection to finish, as 1161 + * it can not be aborted. We don't want to be able to start 1162 + * a new headphone detection from a fresh insert until this 1163 + * one is finished. 1164 + */ 1165 + arizona_hpdet_wait(info); 1194 1166 1195 1167 regmap_update_bits(arizona->regmap, 1196 1168 ARIZONA_JACK_DETECT_DEBOUNCE,
+395
drivers/extcon/extcon-intel-cht-wc.c
··· 1 + /* 2 + * Extcon charger detection driver for Intel Cherrytrail Whiskey Cove PMIC 3 + * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com> 4 + * 5 + * Based on various non upstream patches to support the CHT Whiskey Cove PMIC: 6 + * Copyright (C) 2013-2015 Intel Corporation. All rights reserved. 7 + * 8 + * This program is free software; you can redistribute it and/or modify it 9 + * under the terms and conditions of the GNU General Public License, 10 + * version 2, as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope it will be useful, but WITHOUT 13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 + * more details. 16 + */ 17 + 18 + #include <linux/extcon.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/kernel.h> 21 + #include <linux/mfd/intel_soc_pmic.h> 22 + #include <linux/module.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/regmap.h> 25 + #include <linux/slab.h> 26 + 27 + #define CHT_WC_PHYCTRL 0x5e07 28 + 29 + #define CHT_WC_CHGRCTRL0 0x5e16 30 + #define CHT_WC_CHGRCTRL0_CHGRRESET BIT(0) 31 + #define CHT_WC_CHGRCTRL0_EMRGCHREN BIT(1) 32 + #define CHT_WC_CHGRCTRL0_EXTCHRDIS BIT(2) 33 + #define CHT_WC_CHGRCTRL0_SWCONTROL BIT(3) 34 + #define CHT_WC_CHGRCTRL0_TTLCK_MASK BIT(4) 35 + #define CHT_WC_CHGRCTRL0_CCSM_OFF_MASK BIT(5) 36 + #define CHT_WC_CHGRCTRL0_DBPOFF_MASK BIT(6) 37 + #define CHT_WC_CHGRCTRL0_WDT_NOKICK BIT(7) 38 + 39 + #define CHT_WC_CHGRCTRL1 0x5e17 40 + 41 + #define CHT_WC_USBSRC 0x5e29 42 + #define CHT_WC_USBSRC_STS_MASK GENMASK(1, 0) 43 + #define CHT_WC_USBSRC_STS_SUCCESS 2 44 + #define CHT_WC_USBSRC_STS_FAIL 3 45 + #define CHT_WC_USBSRC_TYPE_SHIFT 2 46 + #define CHT_WC_USBSRC_TYPE_MASK GENMASK(5, 2) 47 + #define CHT_WC_USBSRC_TYPE_NONE 0 48 + #define CHT_WC_USBSRC_TYPE_SDP 1 49 + #define CHT_WC_USBSRC_TYPE_DCP 2 50 + #define CHT_WC_USBSRC_TYPE_CDP 3 51 + #define CHT_WC_USBSRC_TYPE_ACA 4 52 + #define CHT_WC_USBSRC_TYPE_SE1 5 53 + #define CHT_WC_USBSRC_TYPE_MHL 6 54 + #define CHT_WC_USBSRC_TYPE_FLOAT_DP_DN 7 55 + #define CHT_WC_USBSRC_TYPE_OTHER 8 56 + #define CHT_WC_USBSRC_TYPE_DCP_EXTPHY 9 57 + 58 + #define CHT_WC_PWRSRC_IRQ 0x6e03 59 + #define CHT_WC_PWRSRC_IRQ_MASK 0x6e0f 60 + #define CHT_WC_PWRSRC_STS 0x6e1e 61 + #define CHT_WC_PWRSRC_VBUS BIT(0) 62 + #define CHT_WC_PWRSRC_DC BIT(1) 63 + #define CHT_WC_PWRSRC_BAT BIT(2) 64 + #define CHT_WC_PWRSRC_ID_GND BIT(3) 65 + #define CHT_WC_PWRSRC_ID_FLOAT BIT(4) 66 + 67 + #define CHT_WC_VBUS_GPIO_CTLO 0x6e2d 68 + #define CHT_WC_VBUS_GPIO_CTLO_OUTPUT BIT(0) 69 + 70 + enum cht_wc_usb_id { 71 + USB_ID_OTG, 72 + USB_ID_GND, 73 + USB_ID_FLOAT, 74 + USB_RID_A, 75 + USB_RID_B, 76 + USB_RID_C, 77 + }; 78 + 79 + enum cht_wc_mux_select { 80 + MUX_SEL_PMIC = 0, 81 + MUX_SEL_SOC, 82 + }; 83 + 84 + static const unsigned int cht_wc_extcon_cables[] = { 85 + EXTCON_USB, 86 + EXTCON_USB_HOST, 87 + EXTCON_CHG_USB_SDP, 88 + EXTCON_CHG_USB_CDP, 89 + EXTCON_CHG_USB_DCP, 90 + EXTCON_CHG_USB_ACA, 91 + EXTCON_NONE, 92 + }; 93 + 94 + struct cht_wc_extcon_data { 95 + struct device *dev; 96 + struct regmap *regmap; 97 + struct extcon_dev *edev; 98 + unsigned int previous_cable; 99 + bool usb_host; 100 + }; 101 + 102 + static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts) 103 + { 104 + if (pwrsrc_sts & CHT_WC_PWRSRC_ID_GND) 105 + return USB_ID_GND; 106 + if (pwrsrc_sts & CHT_WC_PWRSRC_ID_FLOAT) 107 + return USB_ID_FLOAT; 108 + 109 + /* 110 + * Once we have iio support for the gpadc we should read the USBID 111 + * gpadc channel here and determine ACA role based on that. 112 + */ 113 + return USB_ID_FLOAT; 114 + } 115 + 116 + static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext, 117 + bool ignore_errors) 118 + { 119 + int ret, usbsrc, status; 120 + unsigned long timeout; 121 + 122 + /* Charger detection can take upto 600ms, wait 800ms max. */ 123 + timeout = jiffies + msecs_to_jiffies(800); 124 + do { 125 + ret = regmap_read(ext->regmap, CHT_WC_USBSRC, &usbsrc); 126 + if (ret) { 127 + dev_err(ext->dev, "Error reading usbsrc: %d\n", ret); 128 + return ret; 129 + } 130 + 131 + status = usbsrc & CHT_WC_USBSRC_STS_MASK; 132 + if (status == CHT_WC_USBSRC_STS_SUCCESS || 133 + status == CHT_WC_USBSRC_STS_FAIL) 134 + break; 135 + 136 + msleep(50); /* Wait a bit before retrying */ 137 + } while (time_before(jiffies, timeout)); 138 + 139 + if (status != CHT_WC_USBSRC_STS_SUCCESS) { 140 + if (ignore_errors) 141 + return EXTCON_CHG_USB_SDP; /* Save fallback */ 142 + 143 + if (status == CHT_WC_USBSRC_STS_FAIL) 144 + dev_warn(ext->dev, "Could not detect charger type\n"); 145 + else 146 + dev_warn(ext->dev, "Timeout detecting charger type\n"); 147 + return EXTCON_CHG_USB_SDP; /* Save fallback */ 148 + } 149 + 150 + usbsrc = (usbsrc & CHT_WC_USBSRC_TYPE_MASK) >> CHT_WC_USBSRC_TYPE_SHIFT; 151 + switch (usbsrc) { 152 + default: 153 + dev_warn(ext->dev, 154 + "Unhandled charger type %d, defaulting to SDP\n", 155 + ret); 156 + /* Fall through, treat as SDP */ 157 + case CHT_WC_USBSRC_TYPE_SDP: 158 + case CHT_WC_USBSRC_TYPE_FLOAT_DP_DN: 159 + case CHT_WC_USBSRC_TYPE_OTHER: 160 + return EXTCON_CHG_USB_SDP; 161 + case CHT_WC_USBSRC_TYPE_CDP: 162 + return EXTCON_CHG_USB_CDP; 163 + case CHT_WC_USBSRC_TYPE_DCP: 164 + case CHT_WC_USBSRC_TYPE_DCP_EXTPHY: 165 + case CHT_WC_USBSRC_TYPE_MHL: /* MHL2+ delivers upto 2A, treat as DCP */ 166 + return EXTCON_CHG_USB_DCP; 167 + case CHT_WC_USBSRC_TYPE_ACA: 168 + return EXTCON_CHG_USB_ACA; 169 + } 170 + } 171 + 172 + static void cht_wc_extcon_set_phymux(struct cht_wc_extcon_data *ext, u8 state) 173 + { 174 + int ret; 175 + 176 + ret = regmap_write(ext->regmap, CHT_WC_PHYCTRL, state); 177 + if (ret) 178 + dev_err(ext->dev, "Error writing phyctrl: %d\n", ret); 179 + } 180 + 181 + static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext, 182 + bool enable) 183 + { 184 + int ret, val; 185 + 186 + val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0; 187 + 188 + /* 189 + * The 5V boost converter is enabled through a gpio on the PMIC, since 190 + * there currently is no gpio driver we access the gpio reg directly. 191 + */ 192 + ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO, 193 + CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val); 194 + if (ret) 195 + dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret); 196 + } 197 + 198 + /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */ 199 + static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext, 200 + unsigned int cable, bool state) 201 + { 202 + extcon_set_state_sync(ext->edev, cable, state); 203 + if (cable == EXTCON_CHG_USB_SDP) 204 + extcon_set_state_sync(ext->edev, EXTCON_USB, state); 205 + } 206 + 207 + static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) 208 + { 209 + int ret, pwrsrc_sts, id; 210 + unsigned int cable = EXTCON_NONE; 211 + /* Ignore errors in host mode, as the 5v boost converter is on then */ 212 + bool ignore_get_charger_errors = ext->usb_host; 213 + 214 + ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); 215 + if (ret) { 216 + dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret); 217 + return; 218 + } 219 + 220 + id = cht_wc_extcon_get_id(ext, pwrsrc_sts); 221 + if (id == USB_ID_GND) { 222 + /* The 5v boost causes a false VBUS / SDP detect, skip */ 223 + goto charger_det_done; 224 + } 225 + 226 + /* Plugged into a host/charger or not connected? */ 227 + if (!(pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) { 228 + /* Route D+ and D- to PMIC for future charger detection */ 229 + cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); 230 + goto set_state; 231 + } 232 + 233 + ret = cht_wc_extcon_get_charger(ext, ignore_get_charger_errors); 234 + if (ret >= 0) 235 + cable = ret; 236 + 237 + charger_det_done: 238 + /* Route D+ and D- to SoC for the host or gadget controller */ 239 + cht_wc_extcon_set_phymux(ext, MUX_SEL_SOC); 240 + 241 + set_state: 242 + if (cable != ext->previous_cable) { 243 + cht_wc_extcon_set_state(ext, cable, true); 244 + cht_wc_extcon_set_state(ext, ext->previous_cable, false); 245 + ext->previous_cable = cable; 246 + } 247 + 248 + ext->usb_host = ((id == USB_ID_GND) || (id == USB_RID_A)); 249 + extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); 250 + } 251 + 252 + static irqreturn_t cht_wc_extcon_isr(int irq, void *data) 253 + { 254 + struct cht_wc_extcon_data *ext = data; 255 + int ret, irqs; 256 + 257 + ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_IRQ, &irqs); 258 + if (ret) { 259 + dev_err(ext->dev, "Error reading irqs: %d\n", ret); 260 + return IRQ_NONE; 261 + } 262 + 263 + cht_wc_extcon_pwrsrc_event(ext); 264 + 265 + ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ, irqs); 266 + if (ret) { 267 + dev_err(ext->dev, "Error writing irqs: %d\n", ret); 268 + return IRQ_NONE; 269 + } 270 + 271 + return IRQ_HANDLED; 272 + } 273 + 274 + static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable) 275 + { 276 + int ret, mask, val; 277 + 278 + mask = CHT_WC_CHGRCTRL0_SWCONTROL | CHT_WC_CHGRCTRL0_CCSM_OFF_MASK; 279 + val = enable ? mask : 0; 280 + ret = regmap_update_bits(ext->regmap, CHT_WC_CHGRCTRL0, mask, val); 281 + if (ret) 282 + dev_err(ext->dev, "Error setting sw control: %d\n", ret); 283 + 284 + return ret; 285 + } 286 + 287 + static int cht_wc_extcon_probe(struct platform_device *pdev) 288 + { 289 + struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); 290 + struct cht_wc_extcon_data *ext; 291 + int irq, ret; 292 + 293 + irq = platform_get_irq(pdev, 0); 294 + if (irq < 0) 295 + return irq; 296 + 297 + ext = devm_kzalloc(&pdev->dev, sizeof(*ext), GFP_KERNEL); 298 + if (!ext) 299 + return -ENOMEM; 300 + 301 + ext->dev = &pdev->dev; 302 + ext->regmap = pmic->regmap; 303 + ext->previous_cable = EXTCON_NONE; 304 + 305 + /* Initialize extcon device */ 306 + ext->edev = devm_extcon_dev_allocate(ext->dev, cht_wc_extcon_cables); 307 + if (IS_ERR(ext->edev)) 308 + return PTR_ERR(ext->edev); 309 + 310 + /* 311 + * When a host-cable is detected the BIOS enables an external 5v boost 312 + * converter to power connected devices there are 2 problems with this: 313 + * 1) This gets seen by the external battery charger as a valid Vbus 314 + * supply and it then tries to feed Vsys from this creating a 315 + * feedback loop which causes aprox. 300 mA extra battery drain 316 + * (and unless we drive the external-charger-disable pin high it 317 + * also tries to charge the battery causing even more feedback). 318 + * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply 319 + * Since the external battery charger has its own 5v boost converter 320 + * which does not have these issues, we simply turn the separate 321 + * external 5v boost converter off and leave it off entirely. 322 + */ 323 + cht_wc_extcon_set_5v_boost(ext, false); 324 + 325 + /* Enable sw control */ 326 + ret = cht_wc_extcon_sw_control(ext, true); 327 + if (ret) 328 + return ret; 329 + 330 + /* Register extcon device */ 331 + ret = devm_extcon_dev_register(ext->dev, ext->edev); 332 + if (ret) { 333 + dev_err(ext->dev, "Error registering extcon device: %d\n", ret); 334 + goto disable_sw_control; 335 + } 336 + 337 + /* Route D+ and D- to PMIC for initial charger detection */ 338 + cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); 339 + 340 + /* Get initial state */ 341 + cht_wc_extcon_pwrsrc_event(ext); 342 + 343 + ret = devm_request_threaded_irq(ext->dev, irq, NULL, cht_wc_extcon_isr, 344 + IRQF_ONESHOT, pdev->name, ext); 345 + if (ret) { 346 + dev_err(ext->dev, "Error requesting interrupt: %d\n", ret); 347 + goto disable_sw_control; 348 + } 349 + 350 + /* Unmask irqs */ 351 + ret = regmap_write(ext->regmap, CHT_WC_PWRSRC_IRQ_MASK, 352 + (int)~(CHT_WC_PWRSRC_VBUS | CHT_WC_PWRSRC_ID_GND | 353 + CHT_WC_PWRSRC_ID_FLOAT)); 354 + if (ret) { 355 + dev_err(ext->dev, "Error writing irq-mask: %d\n", ret); 356 + goto disable_sw_control; 357 + } 358 + 359 + platform_set_drvdata(pdev, ext); 360 + 361 + return 0; 362 + 363 + disable_sw_control: 364 + cht_wc_extcon_sw_control(ext, false); 365 + return ret; 366 + } 367 + 368 + static int cht_wc_extcon_remove(struct platform_device *pdev) 369 + { 370 + struct cht_wc_extcon_data *ext = platform_get_drvdata(pdev); 371 + 372 + cht_wc_extcon_sw_control(ext, false); 373 + 374 + return 0; 375 + } 376 + 377 + static const struct platform_device_id cht_wc_extcon_table[] = { 378 + { .name = "cht_wcove_pwrsrc" }, 379 + {}, 380 + }; 381 + MODULE_DEVICE_TABLE(platform, cht_wc_extcon_table); 382 + 383 + static struct platform_driver cht_wc_extcon_driver = { 384 + .probe = cht_wc_extcon_probe, 385 + .remove = cht_wc_extcon_remove, 386 + .id_table = cht_wc_extcon_table, 387 + .driver = { 388 + .name = "cht_wcove_pwrsrc", 389 + }, 390 + }; 391 + module_platform_driver(cht_wc_extcon_driver); 392 + 393 + MODULE_DESCRIPTION("Intel Cherrytrail Whiskey Cove PMIC extcon driver"); 394 + MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 395 + MODULE_LICENSE("GPL v2");
+6
drivers/extcon/extcon-palmas.c
··· 413 413 if (palmas_usb->enable_gpio_id_detection) 414 414 disable_irq_wake(palmas_usb->gpio_id_irq); 415 415 } 416 + 417 + /* check if GPIO states changed while suspend/resume */ 418 + if (palmas_usb->enable_gpio_vbus_detection) 419 + palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb); 420 + palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); 421 + 416 422 return 0; 417 423 }; 418 424 #endif
+4 -6
drivers/extcon/extcon-usb-gpio.c
··· 26 26 #include <linux/platform_device.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/workqueue.h> 29 - #include <linux/acpi.h> 30 29 #include <linux/pinctrl/consumer.h> 31 30 32 31 #define USB_GPIO_DEBOUNCE_MS 20 /* ms */ ··· 110 111 struct usb_extcon_info *info; 111 112 int ret; 112 113 113 - if (!np && !ACPI_HANDLE(dev)) 114 + if (!np) 114 115 return -EINVAL; 115 116 116 117 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); ··· 194 195 } 195 196 196 197 platform_set_drvdata(pdev, info); 197 - device_init_wakeup(dev, true); 198 + device_set_wakeup_capable(&pdev->dev, true); 198 199 199 200 /* Perform initial detection */ 200 201 usb_extcon_detect_cable(&info->wq_detcable.work); ··· 281 282 if (info->vbus_gpiod) 282 283 enable_irq(info->vbus_irq); 283 284 284 - if (!device_may_wakeup(dev)) 285 - queue_delayed_work(system_power_efficient_wq, 286 - &info->wq_detcable, 0); 285 + queue_delayed_work(system_power_efficient_wq, 286 + &info->wq_detcable, 0); 287 287 288 288 return ret; 289 289 }
+1 -21
drivers/extcon/extcon.c
··· 230 230 }; 231 231 232 232 static struct class *extcon_class; 233 - #if defined(CONFIG_ANDROID) 234 - static struct class_compat *switch_class; 235 - #endif /* CONFIG_ANDROID */ 236 233 237 234 static LIST_HEAD(extcon_dev_list); 238 235 static DEFINE_MUTEX(extcon_dev_list_lock); ··· 377 380 for (i = 0; i < edev->max_supported; i++) { 378 381 count += sprintf(buf + count, "%s=%d\n", 379 382 extcon_info[edev->supported_cable[i]].name, 380 - !!(edev->state & (1 << i))); 383 + !!(edev->state & BIT(i))); 381 384 } 382 385 383 386 return count; ··· 1029 1032 if (IS_ERR(extcon_class)) 1030 1033 return PTR_ERR(extcon_class); 1031 1034 extcon_class->dev_groups = extcon_groups; 1032 - 1033 - #if defined(CONFIG_ANDROID) 1034 - switch_class = class_compat_register("switch"); 1035 - if (WARN(!switch_class, "cannot allocate")) 1036 - return -ENOMEM; 1037 - #endif /* CONFIG_ANDROID */ 1038 1035 } 1039 1036 1040 1037 return 0; ··· 1250 1259 put_device(&edev->dev); 1251 1260 goto err_dev; 1252 1261 } 1253 - #if defined(CONFIG_ANDROID) 1254 - if (switch_class) 1255 - ret = class_compat_create_link(switch_class, &edev->dev, NULL); 1256 - #endif /* CONFIG_ANDROID */ 1257 1262 1258 1263 spin_lock_init(&edev->lock); 1259 1264 ··· 1337 1350 kfree(edev->cables); 1338 1351 } 1339 1352 1340 - #if defined(CONFIG_ANDROID) 1341 - if (switch_class) 1342 - class_compat_remove_link(switch_class, &edev->dev, NULL); 1343 - #endif 1344 1353 put_device(&edev->dev); 1345 1354 } 1346 1355 EXPORT_SYMBOL_GPL(extcon_dev_unregister); ··· 1407 1424 1408 1425 static void __exit extcon_class_exit(void) 1409 1426 { 1410 - #if defined(CONFIG_ANDROID) 1411 - class_compat_unregister(switch_class); 1412 - #endif 1413 1427 class_destroy(extcon_class); 1414 1428 } 1415 1429 module_exit(extcon_class_exit);
+1 -1
drivers/firewire/core-topology.c
··· 124 124 node->initiated_reset = SELF_ID_PHY_INITIATOR(sid); 125 125 node->port_count = port_count; 126 126 127 - atomic_set(&node->ref_count, 1); 127 + refcount_set(&node->ref_count, 1); 128 128 INIT_LIST_HEAD(&node->link); 129 129 130 130 return node;
+4 -4
drivers/firewire/core.h
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/types.h> 14 14 15 - #include <linux/atomic.h> 15 + #include <linux/refcount.h> 16 16 17 17 struct device; 18 18 struct fw_card; ··· 184 184 * local node to this node. */ 185 185 u8 max_depth:4; /* Maximum depth to any leaf node */ 186 186 u8 max_hops:4; /* Max hops in this sub tree */ 187 - atomic_t ref_count; 187 + refcount_t ref_count; 188 188 189 189 /* For serializing node topology into a list. */ 190 190 struct list_head link; ··· 197 197 198 198 static inline struct fw_node *fw_node_get(struct fw_node *node) 199 199 { 200 - atomic_inc(&node->ref_count); 200 + refcount_inc(&node->ref_count); 201 201 202 202 return node; 203 203 } 204 204 205 205 static inline void fw_node_put(struct fw_node *node) 206 206 { 207 - if (atomic_dec_and_test(&node->ref_count)) 207 + if (refcount_dec_and_test(&node->ref_count)) 208 208 kfree(node); 209 209 } 210 210
+51 -8
drivers/firmware/google/Kconfig
··· 1 - config GOOGLE_FIRMWARE 1 + menuconfig GOOGLE_FIRMWARE 2 2 bool "Google Firmware Drivers" 3 - depends on X86 4 3 default n 5 4 help 6 5 These firmware drivers are used by Google's servers. They are 7 6 only useful if you are working directly on one of their 8 7 proprietary servers. If in doubt, say "N". 9 8 10 - menu "Google Firmware Drivers" 11 - depends on GOOGLE_FIRMWARE 9 + if GOOGLE_FIRMWARE 12 10 13 11 config GOOGLE_SMI 14 12 tristate "SMI interface for Google platforms" 15 - depends on ACPI && DMI && EFI 13 + depends on X86 && ACPI && DMI && EFI 16 14 select EFI_VARS 17 15 help 18 16 Say Y here if you want to enable SMI callbacks for Google ··· 18 20 clearing the EFI event log and reading and writing NVRAM 19 21 variables. 20 22 23 + config GOOGLE_COREBOOT_TABLE 24 + tristate 25 + depends on GOOGLE_COREBOOT_TABLE_ACPI || GOOGLE_COREBOOT_TABLE_OF 26 + 27 + config GOOGLE_COREBOOT_TABLE_ACPI 28 + tristate "Coreboot Table Access - ACPI" 29 + depends on ACPI 30 + select GOOGLE_COREBOOT_TABLE 31 + help 32 + This option enables the coreboot_table module, which provides other 33 + firmware modules to access to the coreboot table. The coreboot table 34 + pointer is accessed through the ACPI "GOOGCB00" object. 35 + If unsure say N. 36 + 37 + config GOOGLE_COREBOOT_TABLE_OF 38 + tristate "Coreboot Table Access - Device Tree" 39 + depends on OF 40 + select GOOGLE_COREBOOT_TABLE 41 + help 42 + This option enable the coreboot_table module, which provide other 43 + firmware modules to access coreboot table. The coreboot table pointer 44 + is accessed through the device tree node /firmware/coreboot. 45 + If unsure say N. 46 + 21 47 config GOOGLE_MEMCONSOLE 22 - tristate "Firmware Memory Console" 23 - depends on DMI 48 + tristate 49 + depends on GOOGLE_MEMCONSOLE_X86_LEGACY || GOOGLE_MEMCONSOLE_COREBOOT 50 + 51 + config GOOGLE_MEMCONSOLE_X86_LEGACY 52 + tristate "Firmware Memory Console - X86 Legacy support" 53 + depends on X86 && ACPI && DMI 54 + select GOOGLE_MEMCONSOLE 24 55 help 25 56 This option enables the kernel to search for a firmware log in 26 57 the EBDA on Google servers. If found, this log is exported to 27 58 userland in the file /sys/firmware/log. 28 59 29 - endmenu 60 + config GOOGLE_MEMCONSOLE_COREBOOT 61 + tristate "Firmware Memory Console" 62 + depends on GOOGLE_COREBOOT_TABLE 63 + select GOOGLE_MEMCONSOLE 64 + help 65 + This option enables the kernel to search for a firmware log in 66 + the coreboot table. If found, this log is exported to userland 67 + in the file /sys/firmware/log. 68 + 69 + config GOOGLE_VPD 70 + tristate "Vital Product Data" 71 + depends on GOOGLE_COREBOOT_TABLE 72 + help 73 + This option enables the kernel to expose the content of Google VPD 74 + under /sys/firmware/vpd. 75 + 76 + endif # GOOGLE_FIRMWARE
+9 -1
drivers/firmware/google/Makefile
··· 1 1 2 2 obj-$(CONFIG_GOOGLE_SMI) += gsmi.o 3 - obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o 3 + obj-$(CONFIG_GOOGLE_COREBOOT_TABLE) += coreboot_table.o 4 + obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_ACPI) += coreboot_table-acpi.o 5 + obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_OF) += coreboot_table-of.o 6 + obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o 7 + obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT) += memconsole-coreboot.o 8 + obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o 9 + 10 + vpd-sysfs-y := vpd.o vpd_decode.o 11 + obj-$(CONFIG_GOOGLE_VPD) += vpd-sysfs.o
+88
drivers/firmware/google/coreboot_table-acpi.c
··· 1 + /* 2 + * coreboot_table-acpi.c 3 + * 4 + * Using ACPI to locate Coreboot table and provide coreboot table access. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/acpi.h> 19 + #include <linux/device.h> 20 + #include <linux/err.h> 21 + #include <linux/init.h> 22 + #include <linux/io.h> 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/platform_device.h> 26 + 27 + #include "coreboot_table.h" 28 + 29 + static int coreboot_table_acpi_probe(struct platform_device *pdev) 30 + { 31 + phys_addr_t phyaddr; 32 + resource_size_t len; 33 + struct coreboot_table_header __iomem *header = NULL; 34 + struct resource *res; 35 + void __iomem *ptr = NULL; 36 + 37 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 38 + if (!res) 39 + return -EINVAL; 40 + 41 + len = resource_size(res); 42 + if (!res->start || !len) 43 + return -EINVAL; 44 + 45 + phyaddr = res->start; 46 + header = ioremap_cache(phyaddr, sizeof(*header)); 47 + if (header == NULL) 48 + return -ENOMEM; 49 + 50 + ptr = ioremap_cache(phyaddr, 51 + header->header_bytes + header->table_bytes); 52 + iounmap(header); 53 + if (!ptr) 54 + return -ENOMEM; 55 + 56 + return coreboot_table_init(ptr); 57 + } 58 + 59 + static int coreboot_table_acpi_remove(struct platform_device *pdev) 60 + { 61 + return coreboot_table_exit(); 62 + } 63 + 64 + static const struct acpi_device_id cros_coreboot_acpi_match[] = { 65 + { "GOOGCB00", 0 }, 66 + { "BOOT0000", 0 }, 67 + { } 68 + }; 69 + MODULE_DEVICE_TABLE(acpi, cros_coreboot_acpi_match); 70 + 71 + static struct platform_driver coreboot_table_acpi_driver = { 72 + .probe = coreboot_table_acpi_probe, 73 + .remove = coreboot_table_acpi_remove, 74 + .driver = { 75 + .name = "coreboot_table_acpi", 76 + .acpi_match_table = ACPI_PTR(cros_coreboot_acpi_match), 77 + }, 78 + }; 79 + 80 + static int __init coreboot_table_acpi_init(void) 81 + { 82 + return platform_driver_register(&coreboot_table_acpi_driver); 83 + } 84 + 85 + module_init(coreboot_table_acpi_init); 86 + 87 + MODULE_AUTHOR("Google, Inc."); 88 + MODULE_LICENSE("GPL");
+82
drivers/firmware/google/coreboot_table-of.c
··· 1 + /* 2 + * coreboot_table-of.c 3 + * 4 + * Coreboot table access through open firmware. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/device.h> 19 + #include <linux/io.h> 20 + #include <linux/module.h> 21 + #include <linux/of_address.h> 22 + #include <linux/of_platform.h> 23 + #include <linux/platform_device.h> 24 + 25 + #include "coreboot_table.h" 26 + 27 + static int coreboot_table_of_probe(struct platform_device *pdev) 28 + { 29 + struct device_node *fw_dn = pdev->dev.of_node; 30 + void __iomem *ptr; 31 + 32 + ptr = of_iomap(fw_dn, 0); 33 + of_node_put(fw_dn); 34 + if (!ptr) 35 + return -ENOMEM; 36 + 37 + return coreboot_table_init(ptr); 38 + } 39 + 40 + static int coreboot_table_of_remove(struct platform_device *pdev) 41 + { 42 + return coreboot_table_exit(); 43 + } 44 + 45 + static const struct of_device_id coreboot_of_match[] = { 46 + { .compatible = "coreboot" }, 47 + {}, 48 + }; 49 + 50 + static struct platform_driver coreboot_table_of_driver = { 51 + .probe = coreboot_table_of_probe, 52 + .remove = coreboot_table_of_remove, 53 + .driver = { 54 + .name = "coreboot_table_of", 55 + .of_match_table = coreboot_of_match, 56 + }, 57 + }; 58 + 59 + static int __init platform_coreboot_table_of_init(void) 60 + { 61 + struct platform_device *pdev; 62 + struct device_node *of_node; 63 + 64 + /* Limit device creation to the presence of /firmware/coreboot node */ 65 + of_node = of_find_node_by_path("/firmware/coreboot"); 66 + if (!of_node) 67 + return -ENODEV; 68 + 69 + if (!of_match_node(coreboot_of_match, of_node)) 70 + return -ENODEV; 71 + 72 + pdev = of_platform_device_create(of_node, "coreboot_table_of", NULL); 73 + if (!pdev) 74 + return -ENODEV; 75 + 76 + return platform_driver_register(&coreboot_table_of_driver); 77 + } 78 + 79 + module_init(platform_coreboot_table_of_init); 80 + 81 + MODULE_AUTHOR("Google, Inc."); 82 + MODULE_LICENSE("GPL");
+94
drivers/firmware/google/coreboot_table.c
··· 1 + /* 2 + * coreboot_table.c 3 + * 4 + * Module providing coreboot table access. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/err.h> 19 + #include <linux/init.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + 24 + #include "coreboot_table.h" 25 + 26 + struct coreboot_table_entry { 27 + u32 tag; 28 + u32 size; 29 + }; 30 + 31 + static struct coreboot_table_header __iomem *ptr_header; 32 + 33 + /* 34 + * This function parses the coreboot table for an entry that contains the base 35 + * address of the given entry tag. The coreboot table consists of a header 36 + * directly followed by a number of small, variable-sized entries, which each 37 + * contain an identifying tag and their length as the first two fields. 38 + */ 39 + int coreboot_table_find(int tag, void *data, size_t data_size) 40 + { 41 + struct coreboot_table_header header; 42 + struct coreboot_table_entry entry; 43 + void *ptr_entry; 44 + int i; 45 + 46 + if (!ptr_header) 47 + return -EPROBE_DEFER; 48 + 49 + memcpy_fromio(&header, ptr_header, sizeof(header)); 50 + 51 + if (strncmp(header.signature, "LBIO", sizeof(header.signature))) { 52 + pr_warn("coreboot_table: coreboot table missing or corrupt!\n"); 53 + return -ENODEV; 54 + } 55 + 56 + ptr_entry = (void *)ptr_header + header.header_bytes; 57 + 58 + for (i = 0; i < header.table_entries; i++) { 59 + memcpy_fromio(&entry, ptr_entry, sizeof(entry)); 60 + if (entry.tag == tag) { 61 + if (data_size < entry.size) 62 + return -EINVAL; 63 + 64 + memcpy_fromio(data, ptr_entry, entry.size); 65 + 66 + return 0; 67 + } 68 + 69 + ptr_entry += entry.size; 70 + } 71 + 72 + return -ENOENT; 73 + } 74 + EXPORT_SYMBOL(coreboot_table_find); 75 + 76 + int coreboot_table_init(void __iomem *ptr) 77 + { 78 + ptr_header = ptr; 79 + 80 + return 0; 81 + } 82 + EXPORT_SYMBOL(coreboot_table_init); 83 + 84 + int coreboot_table_exit(void) 85 + { 86 + if (ptr_header) 87 + iounmap(ptr_header); 88 + 89 + return 0; 90 + } 91 + EXPORT_SYMBOL(coreboot_table_exit); 92 + 93 + MODULE_AUTHOR("Google, Inc."); 94 + MODULE_LICENSE("GPL");
+50
drivers/firmware/google/coreboot_table.h
··· 1 + /* 2 + * coreboot_table.h 3 + * 4 + * Internal header for coreboot table access. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #ifndef __COREBOOT_TABLE_H 19 + #define __COREBOOT_TABLE_H 20 + 21 + #include <linux/io.h> 22 + 23 + /* List of coreboot entry structures that is used */ 24 + struct lb_cbmem_ref { 25 + uint32_t tag; 26 + uint32_t size; 27 + 28 + uint64_t cbmem_addr; 29 + }; 30 + 31 + /* Coreboot table header structure */ 32 + struct coreboot_table_header { 33 + char signature[4]; 34 + u32 header_bytes; 35 + u32 header_checksum; 36 + u32 table_bytes; 37 + u32 table_checksum; 38 + u32 table_entries; 39 + }; 40 + 41 + /* Retrieve coreboot table entry with tag *tag* and copy it to data */ 42 + int coreboot_table_find(int tag, void *data, size_t data_size); 43 + 44 + /* Initialize coreboot table module given a pointer to iomem */ 45 + int coreboot_table_init(void __iomem *ptr); 46 + 47 + /* Cleanup coreboot table module */ 48 + int coreboot_table_exit(void); 49 + 50 + #endif /* __COREBOOT_TABLE_H */
+109
drivers/firmware/google/memconsole-coreboot.c
··· 1 + /* 2 + * memconsole-coreboot.c 3 + * 4 + * Memory based BIOS console accessed through coreboot table. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + 22 + #include "memconsole.h" 23 + #include "coreboot_table.h" 24 + 25 + #define CB_TAG_CBMEM_CONSOLE 0x17 26 + 27 + /* CBMEM firmware console log descriptor. */ 28 + struct cbmem_cons { 29 + u32 buffer_size; 30 + u32 buffer_cursor; 31 + u8 buffer_body[0]; 32 + } __packed; 33 + 34 + static struct cbmem_cons __iomem *cbmem_console; 35 + 36 + static int memconsole_coreboot_init(phys_addr_t physaddr) 37 + { 38 + struct cbmem_cons __iomem *tmp_cbmc; 39 + 40 + tmp_cbmc = memremap(physaddr, sizeof(*tmp_cbmc), MEMREMAP_WB); 41 + 42 + if (!tmp_cbmc) 43 + return -ENOMEM; 44 + 45 + cbmem_console = memremap(physaddr, 46 + tmp_cbmc->buffer_size + sizeof(*cbmem_console), 47 + MEMREMAP_WB); 48 + memunmap(tmp_cbmc); 49 + 50 + if (!cbmem_console) 51 + return -ENOMEM; 52 + 53 + memconsole_setup(cbmem_console->buffer_body, 54 + min(cbmem_console->buffer_cursor, cbmem_console->buffer_size)); 55 + 56 + return 0; 57 + } 58 + 59 + static int memconsole_probe(struct platform_device *pdev) 60 + { 61 + int ret; 62 + struct lb_cbmem_ref entry; 63 + 64 + ret = coreboot_table_find(CB_TAG_CBMEM_CONSOLE, &entry, sizeof(entry)); 65 + if (ret) 66 + return ret; 67 + 68 + ret = memconsole_coreboot_init(entry.cbmem_addr); 69 + if (ret) 70 + return ret; 71 + 72 + return memconsole_sysfs_init(); 73 + } 74 + 75 + static int memconsole_remove(struct platform_device *pdev) 76 + { 77 + memconsole_exit(); 78 + 79 + if (cbmem_console) 80 + memunmap(cbmem_console); 81 + 82 + return 0; 83 + } 84 + 85 + static struct platform_driver memconsole_driver = { 86 + .probe = memconsole_probe, 87 + .remove = memconsole_remove, 88 + .driver = { 89 + .name = "memconsole", 90 + }, 91 + }; 92 + 93 + static int __init platform_memconsole_init(void) 94 + { 95 + struct platform_device *pdev; 96 + 97 + pdev = platform_device_register_simple("memconsole", -1, NULL, 0); 98 + if (IS_ERR(pdev)) 99 + return PTR_ERR(pdev); 100 + 101 + platform_driver_register(&memconsole_driver); 102 + 103 + return 0; 104 + } 105 + 106 + module_init(platform_memconsole_init); 107 + 108 + MODULE_AUTHOR("Google, Inc."); 109 + MODULE_LICENSE("GPL");
+153
drivers/firmware/google/memconsole-x86-legacy.c
··· 1 + /* 2 + * memconsole-x86-legacy.c 3 + * 4 + * EBDA specific parts of the memory based BIOS console. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/dmi.h> 21 + #include <linux/mm.h> 22 + #include <asm/bios_ebda.h> 23 + #include <linux/acpi.h> 24 + 25 + #include "memconsole.h" 26 + 27 + #define BIOS_MEMCONSOLE_V1_MAGIC 0xDEADBABE 28 + #define BIOS_MEMCONSOLE_V2_MAGIC (('M')|('C'<<8)|('O'<<16)|('N'<<24)) 29 + 30 + struct biosmemcon_ebda { 31 + u32 signature; 32 + union { 33 + struct { 34 + u8 enabled; 35 + u32 buffer_addr; 36 + u16 start; 37 + u16 end; 38 + u16 num_chars; 39 + u8 wrapped; 40 + } __packed v1; 41 + struct { 42 + u32 buffer_addr; 43 + /* Misdocumented as number of pages! */ 44 + u16 num_bytes; 45 + u16 start; 46 + u16 end; 47 + } __packed v2; 48 + }; 49 + } __packed; 50 + 51 + static void found_v1_header(struct biosmemcon_ebda *hdr) 52 + { 53 + pr_info("memconsole: BIOS console v1 EBDA structure found at %p\n", 54 + hdr); 55 + pr_info("memconsole: BIOS console buffer at 0x%.8x, start = %d, end = %d, num = %d\n", 56 + hdr->v1.buffer_addr, hdr->v1.start, 57 + hdr->v1.end, hdr->v1.num_chars); 58 + 59 + memconsole_setup(phys_to_virt(hdr->v1.buffer_addr), hdr->v1.num_chars); 60 + } 61 + 62 + static void found_v2_header(struct biosmemcon_ebda *hdr) 63 + { 64 + pr_info("memconsole: BIOS console v2 EBDA structure found at %p\n", 65 + hdr); 66 + pr_info("memconsole: BIOS console buffer at 0x%.8x, start = %d, end = %d, num_bytes = %d\n", 67 + hdr->v2.buffer_addr, hdr->v2.start, 68 + hdr->v2.end, hdr->v2.num_bytes); 69 + 70 + memconsole_setup(phys_to_virt(hdr->v2.buffer_addr + hdr->v2.start), 71 + hdr->v2.end - hdr->v2.start); 72 + } 73 + 74 + /* 75 + * Search through the EBDA for the BIOS Memory Console, and 76 + * set the global variables to point to it. Return true if found. 77 + */ 78 + static bool memconsole_ebda_init(void) 79 + { 80 + unsigned int address; 81 + size_t length, cur; 82 + 83 + address = get_bios_ebda(); 84 + if (!address) { 85 + pr_info("memconsole: BIOS EBDA non-existent.\n"); 86 + return false; 87 + } 88 + 89 + /* EBDA length is byte 0 of EBDA (in KB) */ 90 + length = *(u8 *)phys_to_virt(address); 91 + length <<= 10; /* convert to bytes */ 92 + 93 + /* 94 + * Search through EBDA for BIOS memory console structure 95 + * note: signature is not necessarily dword-aligned 96 + */ 97 + for (cur = 0; cur < length; cur++) { 98 + struct biosmemcon_ebda *hdr = phys_to_virt(address + cur); 99 + 100 + /* memconsole v1 */ 101 + if (hdr->signature == BIOS_MEMCONSOLE_V1_MAGIC) { 102 + found_v1_header(hdr); 103 + return true; 104 + } 105 + 106 + /* memconsole v2 */ 107 + if (hdr->signature == BIOS_MEMCONSOLE_V2_MAGIC) { 108 + found_v2_header(hdr); 109 + return true; 110 + } 111 + } 112 + 113 + pr_info("memconsole: BIOS console EBDA structure not found!\n"); 114 + return false; 115 + } 116 + 117 + static struct dmi_system_id memconsole_dmi_table[] __initdata = { 118 + { 119 + .ident = "Google Board", 120 + .matches = { 121 + DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."), 122 + }, 123 + }, 124 + {} 125 + }; 126 + MODULE_DEVICE_TABLE(dmi, memconsole_dmi_table); 127 + 128 + static bool __init memconsole_find(void) 129 + { 130 + if (!dmi_check_system(memconsole_dmi_table)) 131 + return false; 132 + 133 + return memconsole_ebda_init(); 134 + } 135 + 136 + static int __init memconsole_x86_init(void) 137 + { 138 + if (!memconsole_find()) 139 + return -ENODEV; 140 + 141 + return memconsole_sysfs_init(); 142 + } 143 + 144 + static void __exit memconsole_x86_exit(void) 145 + { 146 + memconsole_exit(); 147 + } 148 + 149 + module_init(memconsole_x86_init); 150 + module_exit(memconsole_x86_exit); 151 + 152 + MODULE_AUTHOR("Google, Inc."); 153 + MODULE_LICENSE("GPL");
+23 -132
drivers/firmware/google/memconsole.c
··· 1 1 /* 2 2 * memconsole.c 3 3 * 4 - * Infrastructure for importing the BIOS memory based console 5 - * into the kernel log ringbuffer. 4 + * Architecture-independent parts of the memory based BIOS console. 6 5 * 7 - * Copyright 2010 Google Inc. All rights reserved. 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 8 16 */ 9 17 10 - #include <linux/ctype.h> 11 18 #include <linux/init.h> 12 - #include <linux/kernel.h> 13 - #include <linux/string.h> 14 19 #include <linux/sysfs.h> 15 20 #include <linux/kobject.h> 16 21 #include <linux/module.h> 17 - #include <linux/dmi.h> 18 - #include <linux/io.h> 19 - #include <asm/bios_ebda.h> 20 22 21 - #define BIOS_MEMCONSOLE_V1_MAGIC 0xDEADBABE 22 - #define BIOS_MEMCONSOLE_V2_MAGIC (('M')|('C'<<8)|('O'<<16)|('N'<<24)) 23 + #include "memconsole.h" 23 24 24 - struct biosmemcon_ebda { 25 - u32 signature; 26 - union { 27 - struct { 28 - u8 enabled; 29 - u32 buffer_addr; 30 - u16 start; 31 - u16 end; 32 - u16 num_chars; 33 - u8 wrapped; 34 - } __packed v1; 35 - struct { 36 - u32 buffer_addr; 37 - /* Misdocumented as number of pages! */ 38 - u16 num_bytes; 39 - u16 start; 40 - u16 end; 41 - } __packed v2; 42 - }; 43 - } __packed; 44 - 45 - static u32 memconsole_baseaddr; 25 + static char *memconsole_baseaddr; 46 26 static size_t memconsole_length; 47 27 48 28 static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, 49 29 struct bin_attribute *bin_attr, char *buf, 50 30 loff_t pos, size_t count) 51 31 { 52 - char *memconsole; 53 - ssize_t ret; 54 - 55 - memconsole = ioremap_cache(memconsole_baseaddr, memconsole_length); 56 - if (!memconsole) { 57 - pr_err("memconsole: ioremap_cache failed\n"); 58 - return -ENOMEM; 59 - } 60 - ret = memory_read_from_buffer(buf, count, &pos, memconsole, 61 - memconsole_length); 62 - iounmap(memconsole); 63 - return ret; 32 + return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, 33 + memconsole_length); 64 34 } 65 35 66 36 static struct bin_attribute memconsole_bin_attr = { ··· 38 68 .read = memconsole_read, 39 69 }; 40 70 41 - 42 - static void __init found_v1_header(struct biosmemcon_ebda *hdr) 71 + void memconsole_setup(void *baseaddr, size_t length) 43 72 { 44 - pr_info("BIOS console v1 EBDA structure found at %p\n", hdr); 45 - pr_info("BIOS console buffer at 0x%.8x, " 46 - "start = %d, end = %d, num = %d\n", 47 - hdr->v1.buffer_addr, hdr->v1.start, 48 - hdr->v1.end, hdr->v1.num_chars); 49 - 50 - memconsole_length = hdr->v1.num_chars; 51 - memconsole_baseaddr = hdr->v1.buffer_addr; 73 + memconsole_baseaddr = baseaddr; 74 + memconsole_length = length; 52 75 } 76 + EXPORT_SYMBOL(memconsole_setup); 53 77 54 - static void __init found_v2_header(struct biosmemcon_ebda *hdr) 78 + int memconsole_sysfs_init(void) 55 79 { 56 - pr_info("BIOS console v2 EBDA structure found at %p\n", hdr); 57 - pr_info("BIOS console buffer at 0x%.8x, " 58 - "start = %d, end = %d, num_bytes = %d\n", 59 - hdr->v2.buffer_addr, hdr->v2.start, 60 - hdr->v2.end, hdr->v2.num_bytes); 61 - 62 - memconsole_length = hdr->v2.end - hdr->v2.start; 63 - memconsole_baseaddr = hdr->v2.buffer_addr + hdr->v2.start; 64 - } 65 - 66 - /* 67 - * Search through the EBDA for the BIOS Memory Console, and 68 - * set the global variables to point to it. Return true if found. 69 - */ 70 - static bool __init found_memconsole(void) 71 - { 72 - unsigned int address; 73 - size_t length, cur; 74 - 75 - address = get_bios_ebda(); 76 - if (!address) { 77 - pr_info("BIOS EBDA non-existent.\n"); 78 - return false; 79 - } 80 - 81 - /* EBDA length is byte 0 of EBDA (in KB) */ 82 - length = *(u8 *)phys_to_virt(address); 83 - length <<= 10; /* convert to bytes */ 84 - 85 - /* 86 - * Search through EBDA for BIOS memory console structure 87 - * note: signature is not necessarily dword-aligned 88 - */ 89 - for (cur = 0; cur < length; cur++) { 90 - struct biosmemcon_ebda *hdr = phys_to_virt(address + cur); 91 - 92 - /* memconsole v1 */ 93 - if (hdr->signature == BIOS_MEMCONSOLE_V1_MAGIC) { 94 - found_v1_header(hdr); 95 - return true; 96 - } 97 - 98 - /* memconsole v2 */ 99 - if (hdr->signature == BIOS_MEMCONSOLE_V2_MAGIC) { 100 - found_v2_header(hdr); 101 - return true; 102 - } 103 - } 104 - 105 - pr_info("BIOS console EBDA structure not found!\n"); 106 - return false; 107 - } 108 - 109 - static struct dmi_system_id memconsole_dmi_table[] __initdata = { 110 - { 111 - .ident = "Google Board", 112 - .matches = { 113 - DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."), 114 - }, 115 - }, 116 - {} 117 - }; 118 - MODULE_DEVICE_TABLE(dmi, memconsole_dmi_table); 119 - 120 - static int __init memconsole_init(void) 121 - { 122 - if (!dmi_check_system(memconsole_dmi_table)) 123 - return -ENODEV; 124 - 125 - if (!found_memconsole()) 126 - return -ENODEV; 127 - 128 80 memconsole_bin_attr.size = memconsole_length; 129 81 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); 130 82 } 83 + EXPORT_SYMBOL(memconsole_sysfs_init); 131 84 132 - static void __exit memconsole_exit(void) 85 + void memconsole_exit(void) 133 86 { 134 87 sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr); 135 88 } 136 - 137 - module_init(memconsole_init); 138 - module_exit(memconsole_exit); 89 + EXPORT_SYMBOL(memconsole_exit); 139 90 140 91 MODULE_AUTHOR("Google, Inc."); 141 92 MODULE_LICENSE("GPL");
+43
drivers/firmware/google/memconsole.h
··· 1 + /* 2 + * memconsole.h 3 + * 4 + * Internal headers of the memory based BIOS console. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #ifndef __FIRMWARE_GOOGLE_MEMCONSOLE_H 19 + #define __FIRMWARE_GOOGLE_MEMCONSOLE_H 20 + 21 + /* 22 + * memconsole_setup 23 + * 24 + * Initialize the memory console from raw (virtual) base 25 + * address and length. 26 + */ 27 + void memconsole_setup(void *baseaddr, size_t length); 28 + 29 + /* 30 + * memconsole_sysfs_init 31 + * 32 + * Update memory console length and create binary file 33 + * for firmware object. 34 + */ 35 + int memconsole_sysfs_init(void); 36 + 37 + /* memconsole_exit 38 + * 39 + * Unmap the console buffer. 40 + */ 41 + void memconsole_exit(void); 42 + 43 + #endif /* __FIRMWARE_GOOGLE_MEMCONSOLE_H */
+332
drivers/firmware/google/vpd.c
··· 1 + /* 2 + * vpd.c 3 + * 4 + * Driver for exporting VPD content to sysfs. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/ctype.h> 19 + #include <linux/init.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/kobject.h> 23 + #include <linux/list.h> 24 + #include <linux/module.h> 25 + #include <linux/of_address.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/slab.h> 28 + #include <linux/sysfs.h> 29 + 30 + #include "coreboot_table.h" 31 + #include "vpd_decode.h" 32 + 33 + #define CB_TAG_VPD 0x2c 34 + #define VPD_CBMEM_MAGIC 0x43524f53 35 + 36 + static struct kobject *vpd_kobj; 37 + 38 + struct vpd_cbmem { 39 + u32 magic; 40 + u32 version; 41 + u32 ro_size; 42 + u32 rw_size; 43 + u8 blob[0]; 44 + }; 45 + 46 + struct vpd_section { 47 + bool enabled; 48 + const char *name; 49 + char *raw_name; /* the string name_raw */ 50 + struct kobject *kobj; /* vpd/name directory */ 51 + char *baseaddr; 52 + struct bin_attribute bin_attr; /* vpd/name_raw bin_attribute */ 53 + struct list_head attribs; /* key/value in vpd_attrib_info list */ 54 + }; 55 + 56 + struct vpd_attrib_info { 57 + char *key; 58 + const char *value; 59 + struct bin_attribute bin_attr; 60 + struct list_head list; 61 + }; 62 + 63 + static struct vpd_section ro_vpd; 64 + static struct vpd_section rw_vpd; 65 + 66 + static ssize_t vpd_attrib_read(struct file *filp, struct kobject *kobp, 67 + struct bin_attribute *bin_attr, char *buf, 68 + loff_t pos, size_t count) 69 + { 70 + struct vpd_attrib_info *info = bin_attr->private; 71 + 72 + return memory_read_from_buffer(buf, count, &pos, info->value, 73 + info->bin_attr.size); 74 + } 75 + 76 + /* 77 + * vpd_section_check_key_name() 78 + * 79 + * The VPD specification supports only [a-zA-Z0-9_]+ characters in key names but 80 + * old firmware versions may have entries like "S/N" which are problematic when 81 + * exporting them as sysfs attributes. These keys present in old firmwares are 82 + * ignored. 83 + * 84 + * Returns VPD_OK for a valid key name, VPD_FAIL otherwise. 85 + * 86 + * @key: The key name to check 87 + * @key_len: key name length 88 + */ 89 + static int vpd_section_check_key_name(const u8 *key, s32 key_len) 90 + { 91 + int c; 92 + 93 + while (key_len-- > 0) { 94 + c = *key++; 95 + 96 + if (!isalnum(c) && c != '_') 97 + return VPD_FAIL; 98 + } 99 + 100 + return VPD_OK; 101 + } 102 + 103 + static int vpd_section_attrib_add(const u8 *key, s32 key_len, 104 + const u8 *value, s32 value_len, 105 + void *arg) 106 + { 107 + int ret; 108 + struct vpd_section *sec = arg; 109 + struct vpd_attrib_info *info; 110 + 111 + /* 112 + * Return VPD_OK immediately to decode next entry if the current key 113 + * name contains invalid characters. 114 + */ 115 + if (vpd_section_check_key_name(key, key_len) != VPD_OK) 116 + return VPD_OK; 117 + 118 + info = kzalloc(sizeof(*info), GFP_KERNEL); 119 + info->key = kzalloc(key_len + 1, GFP_KERNEL); 120 + if (!info->key) 121 + return -ENOMEM; 122 + 123 + memcpy(info->key, key, key_len); 124 + 125 + sysfs_bin_attr_init(&info->bin_attr); 126 + info->bin_attr.attr.name = info->key; 127 + info->bin_attr.attr.mode = 0444; 128 + info->bin_attr.size = value_len; 129 + info->bin_attr.read = vpd_attrib_read; 130 + info->bin_attr.private = info; 131 + 132 + info->value = value; 133 + 134 + INIT_LIST_HEAD(&info->list); 135 + list_add_tail(&info->list, &sec->attribs); 136 + 137 + ret = sysfs_create_bin_file(sec->kobj, &info->bin_attr); 138 + if (ret) { 139 + kfree(info->key); 140 + return ret; 141 + } 142 + 143 + return 0; 144 + } 145 + 146 + static void vpd_section_attrib_destroy(struct vpd_section *sec) 147 + { 148 + struct vpd_attrib_info *info; 149 + struct vpd_attrib_info *temp; 150 + 151 + list_for_each_entry_safe(info, temp, &sec->attribs, list) { 152 + kfree(info->key); 153 + sysfs_remove_bin_file(sec->kobj, &info->bin_attr); 154 + kfree(info); 155 + } 156 + } 157 + 158 + static ssize_t vpd_section_read(struct file *filp, struct kobject *kobp, 159 + struct bin_attribute *bin_attr, char *buf, 160 + loff_t pos, size_t count) 161 + { 162 + struct vpd_section *sec = bin_attr->private; 163 + 164 + return memory_read_from_buffer(buf, count, &pos, sec->baseaddr, 165 + sec->bin_attr.size); 166 + } 167 + 168 + static int vpd_section_create_attribs(struct vpd_section *sec) 169 + { 170 + s32 consumed; 171 + int ret; 172 + 173 + consumed = 0; 174 + do { 175 + ret = vpd_decode_string(sec->bin_attr.size, sec->baseaddr, 176 + &consumed, vpd_section_attrib_add, sec); 177 + } while (ret == VPD_OK); 178 + 179 + return 0; 180 + } 181 + 182 + static int vpd_section_init(const char *name, struct vpd_section *sec, 183 + phys_addr_t physaddr, size_t size) 184 + { 185 + int ret; 186 + int raw_len; 187 + 188 + sec->baseaddr = memremap(physaddr, size, MEMREMAP_WB); 189 + if (!sec->baseaddr) 190 + return -ENOMEM; 191 + 192 + sec->name = name; 193 + 194 + /* We want to export the raw partion with name ${name}_raw */ 195 + raw_len = strlen(name) + 5; 196 + sec->raw_name = kzalloc(raw_len, GFP_KERNEL); 197 + strncpy(sec->raw_name, name, raw_len); 198 + strncat(sec->raw_name, "_raw", raw_len); 199 + 200 + sysfs_bin_attr_init(&sec->bin_attr); 201 + sec->bin_attr.attr.name = sec->raw_name; 202 + sec->bin_attr.attr.mode = 0444; 203 + sec->bin_attr.size = size; 204 + sec->bin_attr.read = vpd_section_read; 205 + sec->bin_attr.private = sec; 206 + 207 + ret = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr); 208 + if (ret) 209 + goto free_sec; 210 + 211 + sec->kobj = kobject_create_and_add(name, vpd_kobj); 212 + if (!sec->kobj) { 213 + ret = -EINVAL; 214 + goto sysfs_remove; 215 + } 216 + 217 + INIT_LIST_HEAD(&sec->attribs); 218 + vpd_section_create_attribs(sec); 219 + 220 + sec->enabled = true; 221 + 222 + return 0; 223 + 224 + sysfs_remove: 225 + sysfs_remove_bin_file(vpd_kobj, &sec->bin_attr); 226 + 227 + free_sec: 228 + kfree(sec->raw_name); 229 + iounmap(sec->baseaddr); 230 + 231 + return ret; 232 + } 233 + 234 + static int vpd_section_destroy(struct vpd_section *sec) 235 + { 236 + if (sec->enabled) { 237 + vpd_section_attrib_destroy(sec); 238 + kobject_del(sec->kobj); 239 + sysfs_remove_bin_file(vpd_kobj, &sec->bin_attr); 240 + kfree(sec->raw_name); 241 + iounmap(sec->baseaddr); 242 + } 243 + 244 + return 0; 245 + } 246 + 247 + static int vpd_sections_init(phys_addr_t physaddr) 248 + { 249 + struct vpd_cbmem __iomem *temp; 250 + struct vpd_cbmem header; 251 + int ret = 0; 252 + 253 + temp = memremap(physaddr, sizeof(struct vpd_cbmem), MEMREMAP_WB); 254 + if (!temp) 255 + return -ENOMEM; 256 + 257 + memcpy_fromio(&header, temp, sizeof(struct vpd_cbmem)); 258 + iounmap(temp); 259 + 260 + if (header.magic != VPD_CBMEM_MAGIC) 261 + return -ENODEV; 262 + 263 + if (header.ro_size) { 264 + ret = vpd_section_init("ro", &ro_vpd, 265 + physaddr + sizeof(struct vpd_cbmem), 266 + header.ro_size); 267 + if (ret) 268 + return ret; 269 + } 270 + 271 + if (header.rw_size) { 272 + ret = vpd_section_init("rw", &rw_vpd, 273 + physaddr + sizeof(struct vpd_cbmem) + 274 + header.ro_size, header.rw_size); 275 + if (ret) 276 + return ret; 277 + } 278 + 279 + return 0; 280 + } 281 + 282 + static int vpd_probe(struct platform_device *pdev) 283 + { 284 + int ret; 285 + struct lb_cbmem_ref entry; 286 + 287 + ret = coreboot_table_find(CB_TAG_VPD, &entry, sizeof(entry)); 288 + if (ret) 289 + return ret; 290 + 291 + return vpd_sections_init(entry.cbmem_addr); 292 + } 293 + 294 + static struct platform_driver vpd_driver = { 295 + .probe = vpd_probe, 296 + .driver = { 297 + .name = "vpd", 298 + }, 299 + }; 300 + 301 + static int __init vpd_platform_init(void) 302 + { 303 + struct platform_device *pdev; 304 + 305 + pdev = platform_device_register_simple("vpd", -1, NULL, 0); 306 + if (IS_ERR(pdev)) 307 + return PTR_ERR(pdev); 308 + 309 + vpd_kobj = kobject_create_and_add("vpd", firmware_kobj); 310 + if (!vpd_kobj) 311 + return -ENOMEM; 312 + 313 + memset(&ro_vpd, 0, sizeof(ro_vpd)); 314 + memset(&rw_vpd, 0, sizeof(rw_vpd)); 315 + 316 + platform_driver_register(&vpd_driver); 317 + 318 + return 0; 319 + } 320 + 321 + static void __exit vpd_platform_exit(void) 322 + { 323 + vpd_section_destroy(&ro_vpd); 324 + vpd_section_destroy(&rw_vpd); 325 + kobject_del(vpd_kobj); 326 + } 327 + 328 + module_init(vpd_platform_init); 329 + module_exit(vpd_platform_exit); 330 + 331 + MODULE_AUTHOR("Google, Inc."); 332 + MODULE_LICENSE("GPL");
+99
drivers/firmware/google/vpd_decode.c
··· 1 + /* 2 + * vpd_decode.c 3 + * 4 + * Google VPD decoding routines. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/export.h> 19 + 20 + #include "vpd_decode.h" 21 + 22 + static int vpd_decode_len(const s32 max_len, const u8 *in, 23 + s32 *length, s32 *decoded_len) 24 + { 25 + u8 more; 26 + int i = 0; 27 + 28 + if (!length || !decoded_len) 29 + return VPD_FAIL; 30 + 31 + *length = 0; 32 + do { 33 + if (i >= max_len) 34 + return VPD_FAIL; 35 + 36 + more = in[i] & 0x80; 37 + *length <<= 7; 38 + *length |= in[i] & 0x7f; 39 + ++i; 40 + } while (more); 41 + 42 + *decoded_len = i; 43 + 44 + return VPD_OK; 45 + } 46 + 47 + int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed, 48 + vpd_decode_callback callback, void *callback_arg) 49 + { 50 + int type; 51 + int res; 52 + s32 key_len; 53 + s32 value_len; 54 + s32 decoded_len; 55 + const u8 *key; 56 + const u8 *value; 57 + 58 + /* type */ 59 + if (*consumed >= max_len) 60 + return VPD_FAIL; 61 + 62 + type = input_buf[*consumed]; 63 + 64 + switch (type) { 65 + case VPD_TYPE_INFO: 66 + case VPD_TYPE_STRING: 67 + (*consumed)++; 68 + 69 + /* key */ 70 + res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed], 71 + &key_len, &decoded_len); 72 + if (res != VPD_OK || *consumed + decoded_len >= max_len) 73 + return VPD_FAIL; 74 + 75 + *consumed += decoded_len; 76 + key = &input_buf[*consumed]; 77 + *consumed += key_len; 78 + 79 + /* value */ 80 + res = vpd_decode_len(max_len - *consumed, &input_buf[*consumed], 81 + &value_len, &decoded_len); 82 + if (res != VPD_OK || *consumed + decoded_len > max_len) 83 + return VPD_FAIL; 84 + 85 + *consumed += decoded_len; 86 + value = &input_buf[*consumed]; 87 + *consumed += value_len; 88 + 89 + if (type == VPD_TYPE_STRING) 90 + return callback(key, key_len, value, value_len, 91 + callback_arg); 92 + break; 93 + 94 + default: 95 + return VPD_FAIL; 96 + } 97 + 98 + return VPD_OK; 99 + }
+58
drivers/firmware/google/vpd_decode.h
··· 1 + /* 2 + * vpd_decode.h 3 + * 4 + * Google VPD decoding routines. 5 + * 6 + * Copyright 2017 Google Inc. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License v2.0 as published by 10 + * the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #ifndef __VPD_DECODE_H 19 + #define __VPD_DECODE_H 20 + 21 + #include <linux/types.h> 22 + 23 + enum { 24 + VPD_OK = 0, 25 + VPD_FAIL, 26 + }; 27 + 28 + enum { 29 + VPD_TYPE_TERMINATOR = 0, 30 + VPD_TYPE_STRING, 31 + VPD_TYPE_INFO = 0xfe, 32 + VPD_TYPE_IMPLICIT_TERMINATOR = 0xff, 33 + }; 34 + 35 + /* Callback for vpd_decode_string to invoke. */ 36 + typedef int vpd_decode_callback(const u8 *key, s32 key_len, 37 + const u8 *value, s32 value_len, 38 + void *arg); 39 + 40 + /* 41 + * vpd_decode_string 42 + * 43 + * Given the encoded string, this function invokes callback with extracted 44 + * (key, value). The *consumed will be plused the number of bytes consumed in 45 + * this function. 46 + * 47 + * The input_buf points to the first byte of the input buffer. 48 + * 49 + * The *consumed starts from 0, which is actually the next byte to be decoded. 50 + * It can be non-zero to be used in multiple calls. 51 + * 52 + * If one entry is successfully decoded, sends it to callback and returns the 53 + * result. 54 + */ 55 + int vpd_decode_string(const s32 max_len, const u8 *input_buf, s32 *consumed, 56 + vpd_decode_callback callback, void *callback_arg); 57 + 58 + #endif /* __VPD_DECODE_H */
+42
drivers/fpga/Kconfig
··· 20 20 FPGA Regions allow loading FPGA images under control of 21 21 the Device Tree. 22 22 23 + config FPGA_MGR_ICE40_SPI 24 + tristate "Lattice iCE40 SPI" 25 + depends on OF && SPI 26 + help 27 + FPGA manager driver support for Lattice iCE40 FPGAs over SPI. 28 + 23 29 config FPGA_MGR_SOCFPGA 24 30 tristate "Altera SOCFPGA FPGA Manager" 25 31 depends on ARCH_SOCFPGA || COMPILE_TEST ··· 38 32 select REGMAP_MMIO 39 33 help 40 34 FPGA manager driver support for Altera Arria10 SoCFPGA. 35 + 36 + config FPGA_MGR_TS73XX 37 + tristate "Technologic Systems TS-73xx SBC FPGA Manager" 38 + depends on ARCH_EP93XX && MACH_TS72XX 39 + help 40 + FPGA manager driver support for the Altera Cyclone II FPGA 41 + present on the TS-73xx SBC boards. 42 + 43 + config FPGA_MGR_XILINX_SPI 44 + tristate "Xilinx Configuration over Slave Serial (SPI)" 45 + depends on SPI 46 + help 47 + FPGA manager driver support for Xilinx FPGA configuration 48 + over slave serial interface. 41 49 42 50 config FPGA_MGR_ZYNQ_FPGA 43 51 tristate "Xilinx Zynq FPGA" ··· 82 62 freeze bridge is a bridge that exists in the FPGA fabric to 83 63 isolate one region of the FPGA from the busses while that 84 64 region is being reprogrammed. 65 + 66 + config ALTERA_PR_IP_CORE 67 + tristate "Altera Partial Reconfiguration IP Core" 68 + help 69 + Core driver support for Altera Partial Reconfiguration IP component 70 + 71 + config ALTERA_PR_IP_CORE_PLAT 72 + tristate "Platform support of Altera Partial Reconfiguration IP Core" 73 + depends on ALTERA_PR_IP_CORE && OF && HAS_IOMEM 74 + help 75 + Platform driver support for Altera Partial Reconfiguration IP 76 + component 77 + 78 + config XILINX_PR_DECOUPLER 79 + tristate "Xilinx LogiCORE PR Decoupler" 80 + depends on FPGA_BRIDGE 81 + depends on HAS_IOMEM 82 + help 83 + Say Y to enable drivers for Xilinx LogiCORE PR Decoupler. 84 + The PR Decoupler exists in the FPGA fabric to isolate one 85 + region of the FPGA from the busses while that region is 86 + being reprogrammed during partial reconfig. 85 87 86 88 endif # FPGA 87 89
+6
drivers/fpga/Makefile
··· 6 6 obj-$(CONFIG_FPGA) += fpga-mgr.o 7 7 8 8 # FPGA Manager Drivers 9 + obj-$(CONFIG_FPGA_MGR_ICE40_SPI) += ice40-spi.o 9 10 obj-$(CONFIG_FPGA_MGR_SOCFPGA) += socfpga.o 10 11 obj-$(CONFIG_FPGA_MGR_SOCFPGA_A10) += socfpga-a10.o 12 + obj-$(CONFIG_FPGA_MGR_TS73XX) += ts73xx-fpga.o 13 + obj-$(CONFIG_FPGA_MGR_XILINX_SPI) += xilinx-spi.o 11 14 obj-$(CONFIG_FPGA_MGR_ZYNQ_FPGA) += zynq-fpga.o 15 + obj-$(CONFIG_ALTERA_PR_IP_CORE) += altera-pr-ip-core.o 16 + obj-$(CONFIG_ALTERA_PR_IP_CORE_PLAT) += altera-pr-ip-core-plat.o 12 17 13 18 # FPGA Bridge Drivers 14 19 obj-$(CONFIG_FPGA_BRIDGE) += fpga-bridge.o 15 20 obj-$(CONFIG_SOCFPGA_FPGA_BRIDGE) += altera-hps2fpga.o altera-fpga2sdram.o 16 21 obj-$(CONFIG_ALTERA_FREEZE_BRIDGE) += altera-freeze-bridge.o 22 + obj-$(CONFIG_XILINX_PR_DECOUPLER) += xilinx-pr-decoupler.o 17 23 18 24 # High Level Interfaces 19 25 obj-$(CONFIG_FPGA_REGION) += fpga-region.o
+20 -12
drivers/fpga/altera-freeze-bridge.c
··· 28 28 #define FREEZE_CSR_REG_VERSION 12 29 29 30 30 #define FREEZE_CSR_SUPPORTED_VERSION 2 31 + #define FREEZE_CSR_OFFICIAL_VERSION 0xad000003 31 32 32 33 #define FREEZE_CSR_STATUS_FREEZE_REQ_DONE BIT(0) 33 34 #define FREEZE_CSR_STATUS_UNFREEZE_REQ_DONE BIT(1) ··· 204 203 return priv->enable; 205 204 } 206 205 207 - static struct fpga_bridge_ops altera_freeze_br_br_ops = { 206 + static const struct fpga_bridge_ops altera_freeze_br_br_ops = { 208 207 .enable_set = altera_freeze_br_enable_set, 209 208 .enable_show = altera_freeze_br_enable_show, 210 209 }; ··· 219 218 { 220 219 struct device *dev = &pdev->dev; 221 220 struct device_node *np = pdev->dev.of_node; 221 + void __iomem *base_addr; 222 222 struct altera_freeze_br_data *priv; 223 223 struct resource *res; 224 224 u32 status, revision; ··· 227 225 if (!np) 228 226 return -ENODEV; 229 227 228 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 229 + base_addr = devm_ioremap_resource(dev, res); 230 + if (IS_ERR(base_addr)) 231 + return PTR_ERR(base_addr); 232 + 233 + revision = readl(base_addr + FREEZE_CSR_REG_VERSION); 234 + if ((revision != FREEZE_CSR_SUPPORTED_VERSION) && 235 + (revision != FREEZE_CSR_OFFICIAL_VERSION)) { 236 + dev_err(dev, 237 + "%s unexpected revision 0x%x != 0x%x != 0x%x\n", 238 + __func__, revision, FREEZE_CSR_SUPPORTED_VERSION, 239 + FREEZE_CSR_OFFICIAL_VERSION); 240 + return -EINVAL; 241 + } 242 + 230 243 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 231 244 if (!priv) 232 245 return -ENOMEM; 233 246 234 247 priv->dev = dev; 235 248 236 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 237 - priv->base_addr = devm_ioremap_resource(dev, res); 238 - if (IS_ERR(priv->base_addr)) 239 - return PTR_ERR(priv->base_addr); 240 - 241 - status = readl(priv->base_addr + FREEZE_CSR_STATUS_OFFSET); 249 + status = readl(base_addr + FREEZE_CSR_STATUS_OFFSET); 242 250 if (status & FREEZE_CSR_STATUS_UNFREEZE_REQ_DONE) 243 251 priv->enable = 1; 244 252 245 - revision = readl(priv->base_addr + FREEZE_CSR_REG_VERSION); 246 - if (revision != FREEZE_CSR_SUPPORTED_VERSION) 247 - dev_warn(dev, 248 - "%s Freeze Controller unexpected revision %d != %d\n", 249 - __func__, revision, FREEZE_CSR_SUPPORTED_VERSION); 253 + priv->base_addr = base_addr; 250 254 251 255 return fpga_bridge_register(dev, FREEZE_BRIDGE_NAME, 252 256 &altera_freeze_br_br_ops, priv);
+9 -6
drivers/fpga/altera-hps2fpga.c
··· 181 181 (enable ? "enabling" : "disabling")); 182 182 183 183 ret = _alt_hps2fpga_enable_set(priv, enable); 184 - if (ret) { 185 - fpga_bridge_unregister(&pdev->dev); 186 - return ret; 187 - } 184 + if (ret) 185 + goto err; 188 186 } 189 187 } 190 188 191 - return fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops, 192 - priv); 189 + ret = fpga_bridge_register(dev, priv->name, &altera_hps2fpga_br_ops, 190 + priv); 191 + err: 192 + if (ret) 193 + clk_disable_unprepare(priv->clk); 194 + 195 + return ret; 193 196 } 194 197 195 198 static int alt_fpga_bridge_remove(struct platform_device *pdev)
+68
drivers/fpga/altera-pr-ip-core-plat.c
··· 1 + /* 2 + * Driver for Altera Partial Reconfiguration IP Core 3 + * 4 + * Copyright (C) 2016-2017 Intel Corporation 5 + * 6 + * Based on socfpga-a10.c Copyright (C) 2015-2016 Altera Corporation 7 + * by Alan Tull <atull@opensource.altera.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify it 10 + * under the terms and conditions of the GNU General Public License, 11 + * version 2, as published by the Free Software Foundation. 12 + * 13 + * This program is distributed in the hope it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program. If not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + #include <linux/fpga/altera-pr-ip-core.h> 22 + #include <linux/module.h> 23 + #include <linux/of_device.h> 24 + 25 + static int alt_pr_platform_probe(struct platform_device *pdev) 26 + { 27 + struct device *dev = &pdev->dev; 28 + void __iomem *reg_base; 29 + struct resource *res; 30 + 31 + /* First mmio base is for register access */ 32 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 33 + 34 + reg_base = devm_ioremap_resource(dev, res); 35 + 36 + if (IS_ERR(reg_base)) 37 + return PTR_ERR(reg_base); 38 + 39 + return alt_pr_register(dev, reg_base); 40 + } 41 + 42 + static int alt_pr_platform_remove(struct platform_device *pdev) 43 + { 44 + struct device *dev = &pdev->dev; 45 + 46 + return alt_pr_unregister(dev); 47 + } 48 + 49 + static const struct of_device_id alt_pr_of_match[] = { 50 + { .compatible = "altr,a10-pr-ip", }, 51 + {}, 52 + }; 53 + 54 + MODULE_DEVICE_TABLE(of, alt_pr_of_match); 55 + 56 + static struct platform_driver alt_pr_platform_driver = { 57 + .probe = alt_pr_platform_probe, 58 + .remove = alt_pr_platform_remove, 59 + .driver = { 60 + .name = "alt_a10_pr_ip", 61 + .of_match_table = alt_pr_of_match, 62 + }, 63 + }; 64 + 65 + module_platform_driver(alt_pr_platform_driver); 66 + MODULE_AUTHOR("Matthew Gerlach <matthew.gerlach@linux.intel.com>"); 67 + MODULE_DESCRIPTION("Altera Partial Reconfiguration IP Platform Driver"); 68 + MODULE_LICENSE("GPL v2");
+220
drivers/fpga/altera-pr-ip-core.c
··· 1 + /* 2 + * Driver for Altera Partial Reconfiguration IP Core 3 + * 4 + * Copyright (C) 2016-2017 Intel Corporation 5 + * 6 + * Based on socfpga-a10.c Copyright (C) 2015-2016 Altera Corporation 7 + * by Alan Tull <atull@opensource.altera.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify it 10 + * under the terms and conditions of the GNU General Public License, 11 + * version 2, as published by the Free Software Foundation. 12 + * 13 + * This program is distributed in the hope it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program. If not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + #include <linux/delay.h> 22 + #include <linux/fpga/altera-pr-ip-core.h> 23 + #include <linux/fpga/fpga-mgr.h> 24 + #include <linux/module.h> 25 + 26 + #define ALT_PR_DATA_OFST 0x00 27 + #define ALT_PR_CSR_OFST 0x04 28 + 29 + #define ALT_PR_CSR_PR_START BIT(0) 30 + #define ALT_PR_CSR_STATUS_SFT 2 31 + #define ALT_PR_CSR_STATUS_MSK (7 << ALT_PR_CSR_STATUS_SFT) 32 + #define ALT_PR_CSR_STATUS_NRESET (0 << ALT_PR_CSR_STATUS_SFT) 33 + #define ALT_PR_CSR_STATUS_PR_ERR (1 << ALT_PR_CSR_STATUS_SFT) 34 + #define ALT_PR_CSR_STATUS_CRC_ERR (2 << ALT_PR_CSR_STATUS_SFT) 35 + #define ALT_PR_CSR_STATUS_BAD_BITS (3 << ALT_PR_CSR_STATUS_SFT) 36 + #define ALT_PR_CSR_STATUS_PR_IN_PROG (4 << ALT_PR_CSR_STATUS_SFT) 37 + #define ALT_PR_CSR_STATUS_PR_SUCCESS (5 << ALT_PR_CSR_STATUS_SFT) 38 + 39 + struct alt_pr_priv { 40 + void __iomem *reg_base; 41 + }; 42 + 43 + static enum fpga_mgr_states alt_pr_fpga_state(struct fpga_manager *mgr) 44 + { 45 + struct alt_pr_priv *priv = mgr->priv; 46 + const char *err = "unknown"; 47 + enum fpga_mgr_states ret = FPGA_MGR_STATE_UNKNOWN; 48 + u32 val; 49 + 50 + val = readl(priv->reg_base + ALT_PR_CSR_OFST); 51 + 52 + val &= ALT_PR_CSR_STATUS_MSK; 53 + 54 + switch (val) { 55 + case ALT_PR_CSR_STATUS_NRESET: 56 + return FPGA_MGR_STATE_RESET; 57 + 58 + case ALT_PR_CSR_STATUS_PR_ERR: 59 + err = "pr error"; 60 + ret = FPGA_MGR_STATE_WRITE_ERR; 61 + break; 62 + 63 + case ALT_PR_CSR_STATUS_CRC_ERR: 64 + err = "crc error"; 65 + ret = FPGA_MGR_STATE_WRITE_ERR; 66 + break; 67 + 68 + case ALT_PR_CSR_STATUS_BAD_BITS: 69 + err = "bad bits"; 70 + ret = FPGA_MGR_STATE_WRITE_ERR; 71 + break; 72 + 73 + case ALT_PR_CSR_STATUS_PR_IN_PROG: 74 + return FPGA_MGR_STATE_WRITE; 75 + 76 + case ALT_PR_CSR_STATUS_PR_SUCCESS: 77 + return FPGA_MGR_STATE_OPERATING; 78 + 79 + default: 80 + break; 81 + } 82 + 83 + dev_err(&mgr->dev, "encountered error code %d (%s) in %s()\n", 84 + val, err, __func__); 85 + return ret; 86 + } 87 + 88 + static int alt_pr_fpga_write_init(struct fpga_manager *mgr, 89 + struct fpga_image_info *info, 90 + const char *buf, size_t count) 91 + { 92 + struct alt_pr_priv *priv = mgr->priv; 93 + u32 val; 94 + 95 + if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) { 96 + dev_err(&mgr->dev, "%s Partial Reconfiguration flag not set\n", 97 + __func__); 98 + return -EINVAL; 99 + } 100 + 101 + val = readl(priv->reg_base + ALT_PR_CSR_OFST); 102 + 103 + if (val & ALT_PR_CSR_PR_START) { 104 + dev_err(&mgr->dev, 105 + "%s Partial Reconfiguration already started\n", 106 + __func__); 107 + return -EINVAL; 108 + } 109 + 110 + writel(val | ALT_PR_CSR_PR_START, priv->reg_base + ALT_PR_CSR_OFST); 111 + 112 + return 0; 113 + } 114 + 115 + static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf, 116 + size_t count) 117 + { 118 + struct alt_pr_priv *priv = mgr->priv; 119 + u32 *buffer_32 = (u32 *)buf; 120 + size_t i = 0; 121 + 122 + if (count <= 0) 123 + return -EINVAL; 124 + 125 + /* Write out the complete 32-bit chunks */ 126 + while (count >= sizeof(u32)) { 127 + writel(buffer_32[i++], priv->reg_base); 128 + count -= sizeof(u32); 129 + } 130 + 131 + /* Write out remaining non 32-bit chunks */ 132 + switch (count) { 133 + case 3: 134 + writel(buffer_32[i++] & 0x00ffffff, priv->reg_base); 135 + break; 136 + case 2: 137 + writel(buffer_32[i++] & 0x0000ffff, priv->reg_base); 138 + break; 139 + case 1: 140 + writel(buffer_32[i++] & 0x000000ff, priv->reg_base); 141 + break; 142 + case 0: 143 + break; 144 + default: 145 + /* This will never happen */ 146 + return -EFAULT; 147 + } 148 + 149 + if (alt_pr_fpga_state(mgr) == FPGA_MGR_STATE_WRITE_ERR) 150 + return -EIO; 151 + 152 + return 0; 153 + } 154 + 155 + static int alt_pr_fpga_write_complete(struct fpga_manager *mgr, 156 + struct fpga_image_info *info) 157 + { 158 + u32 i = 0; 159 + 160 + do { 161 + switch (alt_pr_fpga_state(mgr)) { 162 + case FPGA_MGR_STATE_WRITE_ERR: 163 + return -EIO; 164 + 165 + case FPGA_MGR_STATE_OPERATING: 166 + dev_info(&mgr->dev, 167 + "successful partial reconfiguration\n"); 168 + return 0; 169 + 170 + default: 171 + break; 172 + } 173 + udelay(1); 174 + } while (info->config_complete_timeout_us > i++); 175 + 176 + dev_err(&mgr->dev, "timed out waiting for write to complete\n"); 177 + return -ETIMEDOUT; 178 + } 179 + 180 + static const struct fpga_manager_ops alt_pr_ops = { 181 + .state = alt_pr_fpga_state, 182 + .write_init = alt_pr_fpga_write_init, 183 + .write = alt_pr_fpga_write, 184 + .write_complete = alt_pr_fpga_write_complete, 185 + }; 186 + 187 + int alt_pr_register(struct device *dev, void __iomem *reg_base) 188 + { 189 + struct alt_pr_priv *priv; 190 + u32 val; 191 + 192 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 193 + if (!priv) 194 + return -ENOMEM; 195 + 196 + priv->reg_base = reg_base; 197 + 198 + val = readl(priv->reg_base + ALT_PR_CSR_OFST); 199 + 200 + dev_dbg(dev, "%s status=%d start=%d\n", __func__, 201 + (val & ALT_PR_CSR_STATUS_MSK) >> ALT_PR_CSR_STATUS_SFT, 202 + (int)(val & ALT_PR_CSR_PR_START)); 203 + 204 + return fpga_mgr_register(dev, dev_name(dev), &alt_pr_ops, priv); 205 + } 206 + EXPORT_SYMBOL_GPL(alt_pr_register); 207 + 208 + int alt_pr_unregister(struct device *dev) 209 + { 210 + dev_dbg(dev, "%s\n", __func__); 211 + 212 + fpga_mgr_unregister(dev); 213 + 214 + return 0; 215 + } 216 + EXPORT_SYMBOL_GPL(alt_pr_unregister); 217 + 218 + MODULE_AUTHOR("Matthew Gerlach <matthew.gerlach@linux.intel.com>"); 219 + MODULE_DESCRIPTION("Altera Partial Reconfiguration IP Core"); 220 + MODULE_LICENSE("GPL v2");
+5 -12
drivers/fpga/fpga-bridge.c
··· 27 27 static struct class *fpga_bridge_class; 28 28 29 29 /* Lock for adding/removing bridges to linked lists*/ 30 - spinlock_t bridge_list_lock; 30 + static spinlock_t bridge_list_lock; 31 31 32 32 static int fpga_bridge_of_node_match(struct device *dev, const void *data) 33 33 { ··· 146 146 int fpga_bridges_enable(struct list_head *bridge_list) 147 147 { 148 148 struct fpga_bridge *bridge; 149 - struct list_head *node; 150 149 int ret; 151 150 152 - list_for_each(node, bridge_list) { 153 - bridge = list_entry(node, struct fpga_bridge, node); 151 + list_for_each_entry(bridge, bridge_list, node) { 154 152 ret = fpga_bridge_enable(bridge); 155 153 if (ret) 156 154 return ret; ··· 170 172 int fpga_bridges_disable(struct list_head *bridge_list) 171 173 { 172 174 struct fpga_bridge *bridge; 173 - struct list_head *node; 174 175 int ret; 175 176 176 - list_for_each(node, bridge_list) { 177 - bridge = list_entry(node, struct fpga_bridge, node); 177 + list_for_each_entry(bridge, bridge_list, node) { 178 178 ret = fpga_bridge_disable(bridge); 179 179 if (ret) 180 180 return ret; ··· 192 196 */ 193 197 void fpga_bridges_put(struct list_head *bridge_list) 194 198 { 195 - struct fpga_bridge *bridge; 196 - struct list_head *node, *next; 199 + struct fpga_bridge *bridge, *next; 197 200 unsigned long flags; 198 201 199 - list_for_each_safe(node, next, bridge_list) { 200 - bridge = list_entry(node, struct fpga_bridge, node); 201 - 202 + list_for_each_entry_safe(bridge, next, bridge_list, node) { 202 203 fpga_bridge_put(bridge); 203 204 204 205 spin_lock_irqsave(&bridge_list_lock, flags);
+1 -1
drivers/fpga/fpga-mgr.c
··· 361 361 }; 362 362 ATTRIBUTE_GROUPS(fpga_mgr); 363 363 364 - struct fpga_manager *__fpga_mgr_get(struct device *dev) 364 + static struct fpga_manager *__fpga_mgr_get(struct device *dev) 365 365 { 366 366 struct fpga_manager *mgr; 367 367 int ret = -ENODEV;
+12 -3
drivers/fpga/fpga-region.c
··· 245 245 mgr = fpga_region_get_manager(region); 246 246 if (IS_ERR(mgr)) { 247 247 pr_err("failed to get fpga region manager\n"); 248 - return PTR_ERR(mgr); 248 + ret = PTR_ERR(mgr); 249 + goto err_put_region; 249 250 } 250 251 251 252 ret = fpga_region_get_bridges(region, overlay); ··· 282 281 fpga_bridges_put(&region->bridge_list); 283 282 err_put_mgr: 284 283 fpga_mgr_put(mgr); 284 + err_put_region: 285 285 fpga_region_put(region); 286 286 287 287 return ret; ··· 339 337 * The overlay must add either firmware-name or external-fpga-config property 340 338 * to the FPGA Region. 341 339 * 342 - * firmware-name : program the FPGA 343 - * external-fpga-config : FPGA is already programmed 340 + * firmware-name : program the FPGA 341 + * external-fpga-config : FPGA is already programmed 342 + * encrypted-fpga-config : FPGA bitstream is encrypted 344 343 * 345 344 * The overlay can add other FPGA regions, but child FPGA regions cannot have a 346 345 * firmware-name property since those regions don't exist yet. ··· 376 373 if (of_property_read_bool(nd->overlay, "external-fpga-config")) 377 374 info->flags |= FPGA_MGR_EXTERNAL_CONFIG; 378 375 376 + if (of_property_read_bool(nd->overlay, "encrypted-fpga-config")) 377 + info->flags |= FPGA_MGR_ENCRYPTED_BITSTREAM; 378 + 379 379 of_property_read_string(nd->overlay, "firmware-name", &firmware_name); 380 380 381 381 of_property_read_u32(nd->overlay, "region-unfreeze-timeout-us", ··· 386 380 387 381 of_property_read_u32(nd->overlay, "region-freeze-timeout-us", 388 382 &info->disable_timeout_us); 383 + 384 + of_property_read_u32(nd->overlay, "config-complete-timeout-us", 385 + &info->config_complete_timeout_us); 389 386 390 387 /* If FPGA was externally programmed, don't specify firmware */ 391 388 if ((info->flags & FPGA_MGR_EXTERNAL_CONFIG) && firmware_name) {
+207
drivers/fpga/ice40-spi.c
··· 1 + /* 2 + * FPGA Manager Driver for Lattice iCE40. 3 + * 4 + * Copyright (c) 2016 Joel Holdsworth 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; version 2 of the License. 9 + * 10 + * This driver adds support to the FPGA manager for configuring the SRAM of 11 + * Lattice iCE40 FPGAs through slave SPI. 12 + */ 13 + 14 + #include <linux/fpga/fpga-mgr.h> 15 + #include <linux/gpio/consumer.h> 16 + #include <linux/module.h> 17 + #include <linux/of_gpio.h> 18 + #include <linux/spi/spi.h> 19 + #include <linux/stringify.h> 20 + 21 + #define ICE40_SPI_MAX_SPEED 25000000 /* Hz */ 22 + #define ICE40_SPI_MIN_SPEED 1000000 /* Hz */ 23 + 24 + #define ICE40_SPI_RESET_DELAY 1 /* us (>200ns) */ 25 + #define ICE40_SPI_HOUSEKEEPING_DELAY 1200 /* us */ 26 + 27 + #define ICE40_SPI_NUM_ACTIVATION_BYTES DIV_ROUND_UP(49, 8) 28 + 29 + struct ice40_fpga_priv { 30 + struct spi_device *dev; 31 + struct gpio_desc *reset; 32 + struct gpio_desc *cdone; 33 + }; 34 + 35 + static enum fpga_mgr_states ice40_fpga_ops_state(struct fpga_manager *mgr) 36 + { 37 + struct ice40_fpga_priv *priv = mgr->priv; 38 + 39 + return gpiod_get_value(priv->cdone) ? FPGA_MGR_STATE_OPERATING : 40 + FPGA_MGR_STATE_UNKNOWN; 41 + } 42 + 43 + static int ice40_fpga_ops_write_init(struct fpga_manager *mgr, 44 + struct fpga_image_info *info, 45 + const char *buf, size_t count) 46 + { 47 + struct ice40_fpga_priv *priv = mgr->priv; 48 + struct spi_device *dev = priv->dev; 49 + struct spi_message message; 50 + struct spi_transfer assert_cs_then_reset_delay = { 51 + .cs_change = 1, 52 + .delay_usecs = ICE40_SPI_RESET_DELAY 53 + }; 54 + struct spi_transfer housekeeping_delay_then_release_cs = { 55 + .delay_usecs = ICE40_SPI_HOUSEKEEPING_DELAY 56 + }; 57 + int ret; 58 + 59 + if ((info->flags & FPGA_MGR_PARTIAL_RECONFIG)) { 60 + dev_err(&dev->dev, 61 + "Partial reconfiguration is not supported\n"); 62 + return -ENOTSUPP; 63 + } 64 + 65 + /* Lock the bus, assert CRESET_B and SS_B and delay >200ns */ 66 + spi_bus_lock(dev->master); 67 + 68 + gpiod_set_value(priv->reset, 1); 69 + 70 + spi_message_init(&message); 71 + spi_message_add_tail(&assert_cs_then_reset_delay, &message); 72 + ret = spi_sync_locked(dev, &message); 73 + 74 + /* Come out of reset */ 75 + gpiod_set_value(priv->reset, 0); 76 + 77 + /* Abort if the chip-select failed */ 78 + if (ret) 79 + goto fail; 80 + 81 + /* Check CDONE is de-asserted i.e. the FPGA is reset */ 82 + if (gpiod_get_value(priv->cdone)) { 83 + dev_err(&dev->dev, "Device reset failed, CDONE is asserted\n"); 84 + ret = -EIO; 85 + goto fail; 86 + } 87 + 88 + /* Wait for the housekeeping to complete, and release SS_B */ 89 + spi_message_init(&message); 90 + spi_message_add_tail(&housekeeping_delay_then_release_cs, &message); 91 + ret = spi_sync_locked(dev, &message); 92 + 93 + fail: 94 + spi_bus_unlock(dev->master); 95 + 96 + return ret; 97 + } 98 + 99 + static int ice40_fpga_ops_write(struct fpga_manager *mgr, 100 + const char *buf, size_t count) 101 + { 102 + struct ice40_fpga_priv *priv = mgr->priv; 103 + 104 + return spi_write(priv->dev, buf, count); 105 + } 106 + 107 + static int ice40_fpga_ops_write_complete(struct fpga_manager *mgr, 108 + struct fpga_image_info *info) 109 + { 110 + struct ice40_fpga_priv *priv = mgr->priv; 111 + struct spi_device *dev = priv->dev; 112 + const u8 padding[ICE40_SPI_NUM_ACTIVATION_BYTES] = {0}; 113 + 114 + /* Check CDONE is asserted */ 115 + if (!gpiod_get_value(priv->cdone)) { 116 + dev_err(&dev->dev, 117 + "CDONE was not asserted after firmware transfer\n"); 118 + return -EIO; 119 + } 120 + 121 + /* Send of zero-padding to activate the firmware */ 122 + return spi_write(dev, padding, sizeof(padding)); 123 + } 124 + 125 + static const struct fpga_manager_ops ice40_fpga_ops = { 126 + .state = ice40_fpga_ops_state, 127 + .write_init = ice40_fpga_ops_write_init, 128 + .write = ice40_fpga_ops_write, 129 + .write_complete = ice40_fpga_ops_write_complete, 130 + }; 131 + 132 + static int ice40_fpga_probe(struct spi_device *spi) 133 + { 134 + struct device *dev = &spi->dev; 135 + struct ice40_fpga_priv *priv; 136 + int ret; 137 + 138 + priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); 139 + if (!priv) 140 + return -ENOMEM; 141 + 142 + priv->dev = spi; 143 + 144 + /* Check board setup data. */ 145 + if (spi->max_speed_hz > ICE40_SPI_MAX_SPEED) { 146 + dev_err(dev, "SPI speed is too high, maximum speed is " 147 + __stringify(ICE40_SPI_MAX_SPEED) "\n"); 148 + return -EINVAL; 149 + } 150 + 151 + if (spi->max_speed_hz < ICE40_SPI_MIN_SPEED) { 152 + dev_err(dev, "SPI speed is too low, minimum speed is " 153 + __stringify(ICE40_SPI_MIN_SPEED) "\n"); 154 + return -EINVAL; 155 + } 156 + 157 + if (spi->mode & SPI_CPHA) { 158 + dev_err(dev, "Bad SPI mode, CPHA not supported\n"); 159 + return -EINVAL; 160 + } 161 + 162 + /* Set up the GPIOs */ 163 + priv->cdone = devm_gpiod_get(dev, "cdone", GPIOD_IN); 164 + if (IS_ERR(priv->cdone)) { 165 + ret = PTR_ERR(priv->cdone); 166 + dev_err(dev, "Failed to get CDONE GPIO: %d\n", ret); 167 + return ret; 168 + } 169 + 170 + priv->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 171 + if (IS_ERR(priv->reset)) { 172 + ret = PTR_ERR(priv->reset); 173 + dev_err(dev, "Failed to get CRESET_B GPIO: %d\n", ret); 174 + return ret; 175 + } 176 + 177 + /* Register with the FPGA manager */ 178 + return fpga_mgr_register(dev, "Lattice iCE40 FPGA Manager", 179 + &ice40_fpga_ops, priv); 180 + } 181 + 182 + static int ice40_fpga_remove(struct spi_device *spi) 183 + { 184 + fpga_mgr_unregister(&spi->dev); 185 + return 0; 186 + } 187 + 188 + static const struct of_device_id ice40_fpga_of_match[] = { 189 + { .compatible = "lattice,ice40-fpga-mgr", }, 190 + {}, 191 + }; 192 + MODULE_DEVICE_TABLE(of, ice40_fpga_of_match); 193 + 194 + static struct spi_driver ice40_fpga_driver = { 195 + .probe = ice40_fpga_probe, 196 + .remove = ice40_fpga_remove, 197 + .driver = { 198 + .name = "ice40spi", 199 + .of_match_table = of_match_ptr(ice40_fpga_of_match), 200 + }, 201 + }; 202 + 203 + module_spi_driver(ice40_fpga_driver); 204 + 205 + MODULE_AUTHOR("Joel Holdsworth <joel@airwebreathe.org.uk>"); 206 + MODULE_DESCRIPTION("Lattice iCE40 FPGA Manager"); 207 + MODULE_LICENSE("GPL v2");
+156
drivers/fpga/ts73xx-fpga.c
··· 1 + /* 2 + * Technologic Systems TS-73xx SBC FPGA loader 3 + * 4 + * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com> 5 + * 6 + * FPGA Manager Driver for the on-board Altera Cyclone II FPGA found on 7 + * TS-7300, heavily based on load_fpga.c in their vendor tree. 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; version 2 of the License. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + */ 18 + 19 + #include <linux/delay.h> 20 + #include <linux/io.h> 21 + #include <linux/module.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/string.h> 24 + #include <linux/iopoll.h> 25 + #include <linux/fpga/fpga-mgr.h> 26 + 27 + #define TS73XX_FPGA_DATA_REG 0 28 + #define TS73XX_FPGA_CONFIG_REG 1 29 + 30 + #define TS73XX_FPGA_WRITE_DONE 0x1 31 + #define TS73XX_FPGA_WRITE_DONE_TIMEOUT 1000 /* us */ 32 + #define TS73XX_FPGA_RESET 0x2 33 + #define TS73XX_FPGA_RESET_LOW_DELAY 30 /* us */ 34 + #define TS73XX_FPGA_RESET_HIGH_DELAY 80 /* us */ 35 + #define TS73XX_FPGA_LOAD_OK 0x4 36 + #define TS73XX_FPGA_CONFIG_LOAD 0x8 37 + 38 + struct ts73xx_fpga_priv { 39 + void __iomem *io_base; 40 + struct device *dev; 41 + }; 42 + 43 + static enum fpga_mgr_states ts73xx_fpga_state(struct fpga_manager *mgr) 44 + { 45 + return FPGA_MGR_STATE_UNKNOWN; 46 + } 47 + 48 + static int ts73xx_fpga_write_init(struct fpga_manager *mgr, 49 + struct fpga_image_info *info, 50 + const char *buf, size_t count) 51 + { 52 + struct ts73xx_fpga_priv *priv = mgr->priv; 53 + 54 + /* Reset the FPGA */ 55 + writeb(0, priv->io_base + TS73XX_FPGA_CONFIG_REG); 56 + udelay(TS73XX_FPGA_RESET_LOW_DELAY); 57 + writeb(TS73XX_FPGA_RESET, priv->io_base + TS73XX_FPGA_CONFIG_REG); 58 + udelay(TS73XX_FPGA_RESET_HIGH_DELAY); 59 + 60 + return 0; 61 + } 62 + 63 + static int ts73xx_fpga_write(struct fpga_manager *mgr, const char *buf, 64 + size_t count) 65 + { 66 + struct ts73xx_fpga_priv *priv = mgr->priv; 67 + size_t i = 0; 68 + int ret; 69 + u8 reg; 70 + 71 + while (count--) { 72 + ret = readb_poll_timeout(priv->io_base + TS73XX_FPGA_CONFIG_REG, 73 + reg, !(reg & TS73XX_FPGA_WRITE_DONE), 74 + 1, TS73XX_FPGA_WRITE_DONE_TIMEOUT); 75 + if (ret < 0) 76 + return ret; 77 + 78 + writeb(buf[i], priv->io_base + TS73XX_FPGA_DATA_REG); 79 + i++; 80 + } 81 + 82 + return 0; 83 + } 84 + 85 + static int ts73xx_fpga_write_complete(struct fpga_manager *mgr, 86 + struct fpga_image_info *info) 87 + { 88 + struct ts73xx_fpga_priv *priv = mgr->priv; 89 + u8 reg; 90 + 91 + usleep_range(1000, 2000); 92 + reg = readb(priv->io_base + TS73XX_FPGA_CONFIG_REG); 93 + reg |= TS73XX_FPGA_CONFIG_LOAD; 94 + writeb(reg, priv->io_base + TS73XX_FPGA_CONFIG_REG); 95 + 96 + usleep_range(1000, 2000); 97 + reg = readb(priv->io_base + TS73XX_FPGA_CONFIG_REG); 98 + reg &= ~TS73XX_FPGA_CONFIG_LOAD; 99 + writeb(reg, priv->io_base + TS73XX_FPGA_CONFIG_REG); 100 + 101 + reg = readb(priv->io_base + TS73XX_FPGA_CONFIG_REG); 102 + if ((reg & TS73XX_FPGA_LOAD_OK) != TS73XX_FPGA_LOAD_OK) 103 + return -ETIMEDOUT; 104 + 105 + return 0; 106 + } 107 + 108 + static const struct fpga_manager_ops ts73xx_fpga_ops = { 109 + .state = ts73xx_fpga_state, 110 + .write_init = ts73xx_fpga_write_init, 111 + .write = ts73xx_fpga_write, 112 + .write_complete = ts73xx_fpga_write_complete, 113 + }; 114 + 115 + static int ts73xx_fpga_probe(struct platform_device *pdev) 116 + { 117 + struct device *kdev = &pdev->dev; 118 + struct ts73xx_fpga_priv *priv; 119 + struct resource *res; 120 + 121 + priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL); 122 + if (!priv) 123 + return -ENOMEM; 124 + 125 + priv->dev = kdev; 126 + 127 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 128 + priv->io_base = devm_ioremap_resource(kdev, res); 129 + if (IS_ERR(priv->io_base)) { 130 + dev_err(kdev, "unable to remap registers\n"); 131 + return PTR_ERR(priv->io_base); 132 + } 133 + 134 + return fpga_mgr_register(kdev, "TS-73xx FPGA Manager", 135 + &ts73xx_fpga_ops, priv); 136 + } 137 + 138 + static int ts73xx_fpga_remove(struct platform_device *pdev) 139 + { 140 + fpga_mgr_unregister(&pdev->dev); 141 + 142 + return 0; 143 + } 144 + 145 + static struct platform_driver ts73xx_fpga_driver = { 146 + .driver = { 147 + .name = "ts73xx-fpga-mgr", 148 + }, 149 + .probe = ts73xx_fpga_probe, 150 + .remove = ts73xx_fpga_remove, 151 + }; 152 + module_platform_driver(ts73xx_fpga_driver); 153 + 154 + MODULE_AUTHOR("Florian Fainelli <f.fainelli@gmail.com>"); 155 + MODULE_DESCRIPTION("TS-73xx FPGA Manager driver"); 156 + MODULE_LICENSE("GPL v2");
+161
drivers/fpga/xilinx-pr-decoupler.c
··· 1 + /* 2 + * Copyright (c) 2017, National Instruments Corp. 3 + * Copyright (c) 2017, Xilix Inc 4 + * 5 + * FPGA Bridge Driver for the Xilinx LogiCORE Partial Reconfiguration 6 + * Decoupler IP Core. 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; version 2 of the License. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/clk.h> 19 + #include <linux/io.h> 20 + #include <linux/kernel.h> 21 + #include <linux/of_device.h> 22 + #include <linux/module.h> 23 + #include <linux/fpga/fpga-bridge.h> 24 + 25 + #define CTRL_CMD_DECOUPLE BIT(0) 26 + #define CTRL_CMD_COUPLE 0 27 + #define CTRL_OFFSET 0 28 + 29 + struct xlnx_pr_decoupler_data { 30 + void __iomem *io_base; 31 + struct clk *clk; 32 + }; 33 + 34 + static inline void xlnx_pr_decoupler_write(struct xlnx_pr_decoupler_data *d, 35 + u32 offset, u32 val) 36 + { 37 + writel(val, d->io_base + offset); 38 + } 39 + 40 + static inline u32 xlnx_pr_decouple_read(const struct xlnx_pr_decoupler_data *d, 41 + u32 offset) 42 + { 43 + return readl(d->io_base + offset); 44 + } 45 + 46 + static int xlnx_pr_decoupler_enable_set(struct fpga_bridge *bridge, bool enable) 47 + { 48 + int err; 49 + struct xlnx_pr_decoupler_data *priv = bridge->priv; 50 + 51 + err = clk_enable(priv->clk); 52 + if (err) 53 + return err; 54 + 55 + if (enable) 56 + xlnx_pr_decoupler_write(priv, CTRL_OFFSET, CTRL_CMD_COUPLE); 57 + else 58 + xlnx_pr_decoupler_write(priv, CTRL_OFFSET, CTRL_CMD_DECOUPLE); 59 + 60 + clk_disable(priv->clk); 61 + 62 + return 0; 63 + } 64 + 65 + static int xlnx_pr_decoupler_enable_show(struct fpga_bridge *bridge) 66 + { 67 + const struct xlnx_pr_decoupler_data *priv = bridge->priv; 68 + u32 status; 69 + int err; 70 + 71 + err = clk_enable(priv->clk); 72 + if (err) 73 + return err; 74 + 75 + status = readl(priv->io_base); 76 + 77 + clk_disable(priv->clk); 78 + 79 + return !status; 80 + } 81 + 82 + static struct fpga_bridge_ops xlnx_pr_decoupler_br_ops = { 83 + .enable_set = xlnx_pr_decoupler_enable_set, 84 + .enable_show = xlnx_pr_decoupler_enable_show, 85 + }; 86 + 87 + static const struct of_device_id xlnx_pr_decoupler_of_match[] = { 88 + { .compatible = "xlnx,pr-decoupler-1.00", }, 89 + { .compatible = "xlnx,pr-decoupler", }, 90 + {}, 91 + }; 92 + MODULE_DEVICE_TABLE(of, xlnx_pr_decoupler_of_match); 93 + 94 + static int xlnx_pr_decoupler_probe(struct platform_device *pdev) 95 + { 96 + struct xlnx_pr_decoupler_data *priv; 97 + int err; 98 + struct resource *res; 99 + 100 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 101 + if (!priv) 102 + return -ENOMEM; 103 + 104 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 105 + priv->io_base = devm_ioremap_resource(&pdev->dev, res); 106 + if (IS_ERR(priv->io_base)) 107 + return PTR_ERR(priv->io_base); 108 + 109 + priv->clk = devm_clk_get(&pdev->dev, "aclk"); 110 + if (IS_ERR(priv->clk)) { 111 + dev_err(&pdev->dev, "input clock not found\n"); 112 + return PTR_ERR(priv->clk); 113 + } 114 + 115 + err = clk_prepare_enable(priv->clk); 116 + if (err) { 117 + dev_err(&pdev->dev, "unable to enable clock\n"); 118 + return err; 119 + } 120 + 121 + clk_disable(priv->clk); 122 + 123 + err = fpga_bridge_register(&pdev->dev, "Xilinx PR Decoupler", 124 + &xlnx_pr_decoupler_br_ops, priv); 125 + 126 + if (err) { 127 + dev_err(&pdev->dev, "unable to register Xilinx PR Decoupler"); 128 + clk_unprepare(priv->clk); 129 + return err; 130 + } 131 + 132 + return 0; 133 + } 134 + 135 + static int xlnx_pr_decoupler_remove(struct platform_device *pdev) 136 + { 137 + struct fpga_bridge *bridge = platform_get_drvdata(pdev); 138 + struct xlnx_pr_decoupler_data *p = bridge->priv; 139 + 140 + fpga_bridge_unregister(&pdev->dev); 141 + 142 + clk_unprepare(p->clk); 143 + 144 + return 0; 145 + } 146 + 147 + static struct platform_driver xlnx_pr_decoupler_driver = { 148 + .probe = xlnx_pr_decoupler_probe, 149 + .remove = xlnx_pr_decoupler_remove, 150 + .driver = { 151 + .name = "xlnx_pr_decoupler", 152 + .of_match_table = of_match_ptr(xlnx_pr_decoupler_of_match), 153 + }, 154 + }; 155 + 156 + module_platform_driver(xlnx_pr_decoupler_driver); 157 + 158 + MODULE_DESCRIPTION("Xilinx Partial Reconfiguration Decoupler"); 159 + MODULE_AUTHOR("Moritz Fischer <mdf@kernel.org>"); 160 + MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>"); 161 + MODULE_LICENSE("GPL v2");
+198
drivers/fpga/xilinx-spi.c
··· 1 + /* 2 + * Xilinx Spartan6 Slave Serial SPI Driver 3 + * 4 + * Copyright (C) 2017 DENX Software Engineering 5 + * 6 + * Anatolij Gustschin <agust@denx.de> 7 + * 8 + * This program is free software; you can redistribute it and/or modify it 9 + * under the terms and conditions of the GNU General Public License, 10 + * version 2, as published by the Free Software Foundation. 11 + * 12 + * Manage Xilinx FPGA firmware that is loaded over SPI using 13 + * the slave serial configuration interface. 14 + */ 15 + 16 + #include <linux/delay.h> 17 + #include <linux/device.h> 18 + #include <linux/fpga/fpga-mgr.h> 19 + #include <linux/gpio/consumer.h> 20 + #include <linux/module.h> 21 + #include <linux/mod_devicetable.h> 22 + #include <linux/of.h> 23 + #include <linux/spi/spi.h> 24 + #include <linux/sizes.h> 25 + 26 + struct xilinx_spi_conf { 27 + struct spi_device *spi; 28 + struct gpio_desc *prog_b; 29 + struct gpio_desc *done; 30 + }; 31 + 32 + static enum fpga_mgr_states xilinx_spi_state(struct fpga_manager *mgr) 33 + { 34 + struct xilinx_spi_conf *conf = mgr->priv; 35 + 36 + if (!gpiod_get_value(conf->done)) 37 + return FPGA_MGR_STATE_RESET; 38 + 39 + return FPGA_MGR_STATE_UNKNOWN; 40 + } 41 + 42 + static int xilinx_spi_write_init(struct fpga_manager *mgr, 43 + struct fpga_image_info *info, 44 + const char *buf, size_t count) 45 + { 46 + struct xilinx_spi_conf *conf = mgr->priv; 47 + const size_t prog_latency_7500us = 7500; 48 + const size_t prog_pulse_1us = 1; 49 + 50 + if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { 51 + dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); 52 + return -EINVAL; 53 + } 54 + 55 + gpiod_set_value(conf->prog_b, 1); 56 + 57 + udelay(prog_pulse_1us); /* min is 500 ns */ 58 + 59 + gpiod_set_value(conf->prog_b, 0); 60 + 61 + if (gpiod_get_value(conf->done)) { 62 + dev_err(&mgr->dev, "Unexpected DONE pin state...\n"); 63 + return -EIO; 64 + } 65 + 66 + /* program latency */ 67 + usleep_range(prog_latency_7500us, prog_latency_7500us + 100); 68 + return 0; 69 + } 70 + 71 + static int xilinx_spi_write(struct fpga_manager *mgr, const char *buf, 72 + size_t count) 73 + { 74 + struct xilinx_spi_conf *conf = mgr->priv; 75 + const char *fw_data = buf; 76 + const char *fw_data_end = fw_data + count; 77 + 78 + while (fw_data < fw_data_end) { 79 + size_t remaining, stride; 80 + int ret; 81 + 82 + remaining = fw_data_end - fw_data; 83 + stride = min_t(size_t, remaining, SZ_4K); 84 + 85 + ret = spi_write(conf->spi, fw_data, stride); 86 + if (ret) { 87 + dev_err(&mgr->dev, "SPI error in firmware write: %d\n", 88 + ret); 89 + return ret; 90 + } 91 + fw_data += stride; 92 + } 93 + 94 + return 0; 95 + } 96 + 97 + static int xilinx_spi_apply_cclk_cycles(struct xilinx_spi_conf *conf) 98 + { 99 + struct spi_device *spi = conf->spi; 100 + const u8 din_data[1] = { 0xff }; 101 + int ret; 102 + 103 + ret = spi_write(conf->spi, din_data, sizeof(din_data)); 104 + if (ret) 105 + dev_err(&spi->dev, "applying CCLK cycles failed: %d\n", ret); 106 + 107 + return ret; 108 + } 109 + 110 + static int xilinx_spi_write_complete(struct fpga_manager *mgr, 111 + struct fpga_image_info *info) 112 + { 113 + struct xilinx_spi_conf *conf = mgr->priv; 114 + unsigned long timeout; 115 + int ret; 116 + 117 + if (gpiod_get_value(conf->done)) 118 + return xilinx_spi_apply_cclk_cycles(conf); 119 + 120 + timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); 121 + 122 + while (time_before(jiffies, timeout)) { 123 + 124 + ret = xilinx_spi_apply_cclk_cycles(conf); 125 + if (ret) 126 + return ret; 127 + 128 + if (gpiod_get_value(conf->done)) 129 + return xilinx_spi_apply_cclk_cycles(conf); 130 + } 131 + 132 + dev_err(&mgr->dev, "Timeout after config data transfer.\n"); 133 + return -ETIMEDOUT; 134 + } 135 + 136 + static const struct fpga_manager_ops xilinx_spi_ops = { 137 + .state = xilinx_spi_state, 138 + .write_init = xilinx_spi_write_init, 139 + .write = xilinx_spi_write, 140 + .write_complete = xilinx_spi_write_complete, 141 + }; 142 + 143 + static int xilinx_spi_probe(struct spi_device *spi) 144 + { 145 + struct xilinx_spi_conf *conf; 146 + 147 + conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL); 148 + if (!conf) 149 + return -ENOMEM; 150 + 151 + conf->spi = spi; 152 + 153 + /* PROGRAM_B is active low */ 154 + conf->prog_b = devm_gpiod_get(&spi->dev, "prog_b", GPIOD_OUT_LOW); 155 + if (IS_ERR(conf->prog_b)) { 156 + dev_err(&spi->dev, "Failed to get PROGRAM_B gpio: %ld\n", 157 + PTR_ERR(conf->prog_b)); 158 + return PTR_ERR(conf->prog_b); 159 + } 160 + 161 + conf->done = devm_gpiod_get(&spi->dev, "done", GPIOD_IN); 162 + if (IS_ERR(conf->done)) { 163 + dev_err(&spi->dev, "Failed to get DONE gpio: %ld\n", 164 + PTR_ERR(conf->done)); 165 + return PTR_ERR(conf->done); 166 + } 167 + 168 + return fpga_mgr_register(&spi->dev, "Xilinx Slave Serial FPGA Manager", 169 + &xilinx_spi_ops, conf); 170 + } 171 + 172 + static int xilinx_spi_remove(struct spi_device *spi) 173 + { 174 + fpga_mgr_unregister(&spi->dev); 175 + 176 + return 0; 177 + } 178 + 179 + static const struct of_device_id xlnx_spi_of_match[] = { 180 + { .compatible = "xlnx,fpga-slave-serial", }, 181 + {} 182 + }; 183 + MODULE_DEVICE_TABLE(of, xlnx_spi_of_match); 184 + 185 + static struct spi_driver xilinx_slave_spi_driver = { 186 + .driver = { 187 + .name = "xlnx-slave-spi", 188 + .of_match_table = of_match_ptr(xlnx_spi_of_match), 189 + }, 190 + .probe = xilinx_spi_probe, 191 + .remove = xilinx_spi_remove, 192 + }; 193 + 194 + module_spi_driver(xilinx_slave_spi_driver) 195 + 196 + MODULE_LICENSE("GPL v2"); 197 + MODULE_AUTHOR("Anatolij Gustschin <agust@denx.de>"); 198 + MODULE_DESCRIPTION("Load Xilinx FPGA firmware over SPI");
+25 -3
drivers/fpga/zynq-fpga.c
··· 72 72 #define CTRL_PCAP_PR_MASK BIT(27) 73 73 /* Enable PCAP */ 74 74 #define CTRL_PCAP_MODE_MASK BIT(26) 75 + /* Lower rate to allow decrypt on the fly */ 76 + #define CTRL_PCAP_RATE_EN_MASK BIT(25) 77 + /* System booted in secure mode */ 78 + #define CTRL_SEC_EN_MASK BIT(7) 75 79 76 80 /* Miscellaneous Control Register bit definitions */ 77 81 /* Internal PCAP loopback */ ··· 270 266 if (err) 271 267 return err; 272 268 269 + /* check if bitstream is encrypted & and system's still secure */ 270 + if (info->flags & FPGA_MGR_ENCRYPTED_BITSTREAM) { 271 + ctrl = zynq_fpga_read(priv, CTRL_OFFSET); 272 + if (!(ctrl & CTRL_SEC_EN_MASK)) { 273 + dev_err(&mgr->dev, 274 + "System not secure, can't use crypted bitstreams\n"); 275 + err = -EINVAL; 276 + goto out_err; 277 + } 278 + } 279 + 273 280 /* don't globally reset PL if we're doing partial reconfig */ 274 281 if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) { 275 282 if (!zynq_fpga_has_sync(buf, count)) { ··· 352 337 353 338 /* set configuration register with following options: 354 339 * - enable PCAP interface 355 - * - set throughput for maximum speed 340 + * - set throughput for maximum speed (if bistream not crypted) 356 341 * - set CPU in user mode 357 342 */ 358 343 ctrl = zynq_fpga_read(priv, CTRL_OFFSET); 359 - zynq_fpga_write(priv, CTRL_OFFSET, 360 - (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK | ctrl)); 344 + if (info->flags & FPGA_MGR_ENCRYPTED_BITSTREAM) 345 + zynq_fpga_write(priv, CTRL_OFFSET, 346 + (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK 347 + | CTRL_PCAP_RATE_EN_MASK | ctrl)); 348 + else 349 + zynq_fpga_write(priv, CTRL_OFFSET, 350 + (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK 351 + | ctrl)); 352 + 361 353 362 354 /* We expect that the command queue is empty right now. */ 363 355 status = zynq_fpga_read(priv, STATUS_OFFSET);
+8 -15
drivers/gpio/gpiolib.c
··· 1035 1035 1036 1036 cdev_init(&gdev->chrdev, &gpio_fileops); 1037 1037 gdev->chrdev.owner = THIS_MODULE; 1038 - gdev->chrdev.kobj.parent = &gdev->dev.kobj; 1039 1038 gdev->dev.devt = MKDEV(MAJOR(gpio_devt), gdev->id); 1040 - status = cdev_add(&gdev->chrdev, gdev->dev.devt, 1); 1041 - if (status < 0) 1042 - chip_warn(gdev->chip, "failed to add char device %d:%d\n", 1043 - MAJOR(gpio_devt), gdev->id); 1044 - else 1045 - chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n", 1046 - MAJOR(gpio_devt), gdev->id); 1047 - status = device_add(&gdev->dev); 1039 + 1040 + status = cdev_device_add(&gdev->chrdev, &gdev->dev); 1048 1041 if (status) 1049 - goto err_remove_chardev; 1042 + return status; 1043 + 1044 + chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n", 1045 + MAJOR(gpio_devt), gdev->id); 1050 1046 1051 1047 status = gpiochip_sysfs_register(gdev); 1052 1048 if (status) ··· 1057 1061 return 0; 1058 1062 1059 1063 err_remove_device: 1060 - device_del(&gdev->dev); 1061 - err_remove_chardev: 1062 - cdev_del(&gdev->chrdev); 1064 + cdev_device_del(&gdev->chrdev, &gdev->dev); 1063 1065 return status; 1064 1066 } 1065 1067 ··· 1341 1347 * be removed, else it will be dangling until the last user is 1342 1348 * gone. 1343 1349 */ 1344 - cdev_del(&gdev->chrdev); 1345 - device_del(&gdev->dev); 1350 + cdev_device_del(&gdev->chrdev, &gdev->dev); 1346 1351 put_device(&gdev->dev); 1347 1352 } 1348 1353 EXPORT_SYMBOL_GPL(gpiochip_remove);
+5 -5
drivers/hv/channel.c
··· 333 333 * Gpadl is u32 and we are using a pointer which could 334 334 * be 64-bit 335 335 * This is governed by the guest/host protocol and 336 - * so the hypervisor gurantees that this is ok. 336 + * so the hypervisor guarantees that this is ok. 337 337 */ 338 338 for (i = 0; i < pfncurr; i++) 339 339 gpadl_body->pfn[i] = slow_virt_to_phys( ··· 380 380 } 381 381 382 382 /* 383 - * vmbus_establish_gpadl - Estabish a GPADL for the specified buffer 383 + * vmbus_establish_gpadl - Establish a GPADL for the specified buffer 384 384 * 385 385 * @channel: a channel 386 386 * @kbuffer: from kmalloc or vmalloc ··· 731 731 /* Setup the descriptor */ 732 732 desc.type = VM_PKT_DATA_USING_GPA_DIRECT; 733 733 desc.flags = flags; 734 - desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ 734 + desc.dataoffset8 = descsize >> 3; /* in 8-bytes granularity */ 735 735 desc.length8 = (u16)(packetlen_aligned >> 3); 736 736 desc.transactionid = requestid; 737 737 desc.rangecount = pagecount; ··· 792 792 /* Setup the descriptor */ 793 793 desc->type = VM_PKT_DATA_USING_GPA_DIRECT; 794 794 desc->flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; 795 - desc->dataoffset8 = desc_size >> 3; /* in 8-bytes grandularity */ 795 + desc->dataoffset8 = desc_size >> 3; /* in 8-bytes granularity */ 796 796 desc->length8 = (u16)(packetlen_aligned >> 3); 797 797 desc->transactionid = requestid; 798 798 desc->rangecount = 1; ··· 842 842 /* Setup the descriptor */ 843 843 desc.type = VM_PKT_DATA_USING_GPA_DIRECT; 844 844 desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; 845 - desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ 845 + desc.dataoffset8 = descsize >> 3; /* in 8-bytes granularity */ 846 846 desc.length8 = (u16)(packetlen_aligned >> 3); 847 847 desc.transactionid = requestid; 848 848 desc.rangecount = 1;
+24 -24
drivers/hv/channel_mgmt.c
··· 1080 1080 } 1081 1081 1082 1082 /* Channel message dispatch table */ 1083 - struct vmbus_channel_message_table_entry 1084 - channel_message_table[CHANNELMSG_COUNT] = { 1085 - {CHANNELMSG_INVALID, 0, NULL}, 1086 - {CHANNELMSG_OFFERCHANNEL, 0, vmbus_onoffer}, 1087 - {CHANNELMSG_RESCIND_CHANNELOFFER, 0, vmbus_onoffer_rescind}, 1088 - {CHANNELMSG_REQUESTOFFERS, 0, NULL}, 1089 - {CHANNELMSG_ALLOFFERS_DELIVERED, 1, vmbus_onoffers_delivered}, 1090 - {CHANNELMSG_OPENCHANNEL, 0, NULL}, 1091 - {CHANNELMSG_OPENCHANNEL_RESULT, 1, vmbus_onopen_result}, 1092 - {CHANNELMSG_CLOSECHANNEL, 0, NULL}, 1093 - {CHANNELMSG_GPADL_HEADER, 0, NULL}, 1094 - {CHANNELMSG_GPADL_BODY, 0, NULL}, 1095 - {CHANNELMSG_GPADL_CREATED, 1, vmbus_ongpadl_created}, 1096 - {CHANNELMSG_GPADL_TEARDOWN, 0, NULL}, 1097 - {CHANNELMSG_GPADL_TORNDOWN, 1, vmbus_ongpadl_torndown}, 1098 - {CHANNELMSG_RELID_RELEASED, 0, NULL}, 1099 - {CHANNELMSG_INITIATE_CONTACT, 0, NULL}, 1100 - {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response}, 1101 - {CHANNELMSG_UNLOAD, 0, NULL}, 1102 - {CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response}, 1103 - {CHANNELMSG_18, 0, NULL}, 1104 - {CHANNELMSG_19, 0, NULL}, 1105 - {CHANNELMSG_20, 0, NULL}, 1106 - {CHANNELMSG_TL_CONNECT_REQUEST, 0, NULL}, 1083 + const struct vmbus_channel_message_table_entry 1084 + channel_message_table[CHANNELMSG_COUNT] = { 1085 + { CHANNELMSG_INVALID, 0, NULL }, 1086 + { CHANNELMSG_OFFERCHANNEL, 0, vmbus_onoffer }, 1087 + { CHANNELMSG_RESCIND_CHANNELOFFER, 0, vmbus_onoffer_rescind }, 1088 + { CHANNELMSG_REQUESTOFFERS, 0, NULL }, 1089 + { CHANNELMSG_ALLOFFERS_DELIVERED, 1, vmbus_onoffers_delivered }, 1090 + { CHANNELMSG_OPENCHANNEL, 0, NULL }, 1091 + { CHANNELMSG_OPENCHANNEL_RESULT, 1, vmbus_onopen_result }, 1092 + { CHANNELMSG_CLOSECHANNEL, 0, NULL }, 1093 + { CHANNELMSG_GPADL_HEADER, 0, NULL }, 1094 + { CHANNELMSG_GPADL_BODY, 0, NULL }, 1095 + { CHANNELMSG_GPADL_CREATED, 1, vmbus_ongpadl_created }, 1096 + { CHANNELMSG_GPADL_TEARDOWN, 0, NULL }, 1097 + { CHANNELMSG_GPADL_TORNDOWN, 1, vmbus_ongpadl_torndown }, 1098 + { CHANNELMSG_RELID_RELEASED, 0, NULL }, 1099 + { CHANNELMSG_INITIATE_CONTACT, 0, NULL }, 1100 + { CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response }, 1101 + { CHANNELMSG_UNLOAD, 0, NULL }, 1102 + { CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response }, 1103 + { CHANNELMSG_18, 0, NULL }, 1104 + { CHANNELMSG_19, 0, NULL }, 1105 + { CHANNELMSG_20, 0, NULL }, 1106 + { CHANNELMSG_TL_CONNECT_REQUEST, 0, NULL }, 1107 1107 }; 1108 1108 1109 1109 /*
+33 -30
drivers/hv/connection.c
··· 296 296 297 297 /* 298 298 * vmbus_on_event - Process a channel event notification 299 + * 300 + * For batched channels (default) optimize host to guest signaling 301 + * by ensuring: 302 + * 1. While reading the channel, we disable interrupts from host. 303 + * 2. Ensure that we process all posted messages from the host 304 + * before returning from this callback. 305 + * 3. Once we return, enable signaling from the host. Once this 306 + * state is set we check to see if additional packets are 307 + * available to read. In this case we repeat the process. 308 + * If this tasklet has been running for a long time 309 + * then reschedule ourselves. 299 310 */ 300 311 void vmbus_on_event(unsigned long data) 301 312 { 302 313 struct vmbus_channel *channel = (void *) data; 303 - void (*callback_fn)(void *); 314 + unsigned long time_limit = jiffies + 2; 304 315 305 - /* 306 - * A channel once created is persistent even when there 307 - * is no driver handling the device. An unloading driver 308 - * sets the onchannel_callback to NULL on the same CPU 309 - * as where this interrupt is handled (in an interrupt context). 310 - * Thus, checking and invoking the driver specific callback takes 311 - * care of orderly unloading of the driver. 312 - */ 313 - callback_fn = READ_ONCE(channel->onchannel_callback); 314 - if (unlikely(callback_fn == NULL)) 315 - return; 316 + do { 317 + void (*callback_fn)(void *); 316 318 317 - (*callback_fn)(channel->channel_callback_context); 318 - 319 - if (channel->callback_mode == HV_CALL_BATCHED) { 320 - /* 321 - * This callback reads the messages sent by the host. 322 - * We can optimize host to guest signaling by ensuring: 323 - * 1. While reading the channel, we disable interrupts from 324 - * host. 325 - * 2. Ensure that we process all posted messages from the host 326 - * before returning from this callback. 327 - * 3. Once we return, enable signaling from the host. Once this 328 - * state is set we check to see if additional packets are 329 - * available to read. In this case we repeat the process. 319 + /* A channel once created is persistent even when 320 + * there is no driver handling the device. An 321 + * unloading driver sets the onchannel_callback to NULL. 330 322 */ 331 - if (hv_end_read(&channel->inbound) != 0) { 332 - hv_begin_read(&channel->inbound); 323 + callback_fn = READ_ONCE(channel->onchannel_callback); 324 + if (unlikely(callback_fn == NULL)) 325 + return; 333 326 334 - tasklet_schedule(&channel->callback_event); 335 - } 336 - } 327 + (*callback_fn)(channel->channel_callback_context); 328 + 329 + if (channel->callback_mode != HV_CALL_BATCHED) 330 + return; 331 + 332 + if (likely(hv_end_read(&channel->inbound) == 0)) 333 + return; 334 + 335 + hv_begin_read(&channel->inbound); 336 + } while (likely(time_before(jiffies, time_limit))); 337 + 338 + /* The time limit (2 jiffies) has been reached */ 339 + tasklet_schedule(&channel->callback_event); 337 340 } 338 341 339 342 /*
+4 -1
drivers/hv/hv.c
··· 254 254 shared_sint.as_uint64 = 0; 255 255 shared_sint.vector = HYPERVISOR_CALLBACK_VECTOR; 256 256 shared_sint.masked = false; 257 - shared_sint.auto_eoi = true; 257 + if (ms_hyperv.hints & HV_X64_DEPRECATING_AEOI_RECOMMENDED) 258 + shared_sint.auto_eoi = false; 259 + else 260 + shared_sint.auto_eoi = true; 258 261 259 262 hv_set_synint_state(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, 260 263 shared_sint.as_uint64);
-2
drivers/hv/hv_balloon.c
··· 722 722 5*HZ); 723 723 post_status(&dm_device); 724 724 } 725 - 726 - return; 727 725 } 728 726 729 727 static void hv_online_page(struct page *pg)
-2
drivers/hv/hv_fcopy.c
··· 186 186 } 187 187 } 188 188 kfree(smsg_out); 189 - 190 - return; 191 189 } 192 190 193 191 /*
+5 -7
drivers/hv/hv_kvp.c
··· 69 69 * 70 70 * While the request/response protocol is guaranteed by the host, we further 71 71 * ensure this by serializing packet processing in this driver - we do not 72 - * read additional packets from the VMBUs until the current packet is fully 72 + * read additional packets from the VMBUS until the current packet is fully 73 73 * handled. 74 74 */ 75 75 ··· 397 397 * the max lengths specified. We will however, reserve room 398 398 * for the string terminating character - in the utf16s_utf8s() 399 399 * function we limit the size of the buffer where the converted 400 - * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to gaurantee 400 + * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to guarantee 401 401 * that the strings can be properly terminated! 402 402 */ 403 403 ··· 483 483 } 484 484 485 485 kfree(message); 486 - 487 - return; 488 486 } 489 487 490 488 /* ··· 531 533 */ 532 534 if (error) { 533 535 /* 534 - * Something failed or we have timedout; 536 + * Something failed or we have timed out; 535 537 * terminate the current host-side iteration. 536 538 */ 537 539 goto response_done; ··· 605 607 * This callback is invoked when we get a KVP message from the host. 606 608 * The host ensures that only one KVP transaction can be active at a time. 607 609 * KVP implementation in Linux needs to forward the key to a user-mde 608 - * component to retrive the corresponding value. Consequently, we cannot 609 - * respond to the host in the conext of this callback. Since the host 610 + * component to retrieve the corresponding value. Consequently, we cannot 611 + * respond to the host in the context of this callback. Since the host 610 612 * guarantees that at most only one transaction can be active at a time, 611 613 * we stash away the transaction state in a set of global variables. 612 614 */
-2
drivers/hv/hv_snapshot.c
··· 212 212 } 213 213 214 214 kfree(vss_msg); 215 - 216 - return; 217 215 } 218 216 219 217 static void vss_handle_request(struct work_struct *dummy)
+9 -20
drivers/hv/hyperv_vmbus.h
··· 218 218 219 219 struct hv_context { 220 220 /* We only support running on top of Hyper-V 221 - * So at this point this really can only contain the Hyper-V ID 222 - */ 221 + * So at this point this really can only contain the Hyper-V ID 222 + */ 223 223 u64 guestid; 224 224 225 225 void *tsc_page; ··· 247 247 }; 248 248 249 249 extern struct hv_context hv_context; 250 - 251 - struct hv_ring_buffer_debug_info { 252 - u32 current_interrupt_mask; 253 - u32 current_read_index; 254 - u32 current_write_index; 255 - u32 bytes_avail_toread; 256 - u32 bytes_avail_towrite; 257 - }; 258 250 259 251 /* Hv Interface */ 260 252 ··· 280 288 int hv_ringbuffer_read(struct vmbus_channel *channel, 281 289 void *buffer, u32 buflen, u32 *buffer_actual_len, 282 290 u64 *requestid, bool raw); 283 - 284 - void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info, 285 - struct hv_ring_buffer_debug_info *debug_info); 286 291 287 292 /* 288 293 * Maximum channels is determined by the size of the interrupt page ··· 365 376 void (*message_handler)(struct vmbus_channel_message_header *msg); 366 377 }; 367 378 368 - extern struct vmbus_channel_message_table_entry 379 + extern const struct vmbus_channel_message_table_entry 369 380 channel_message_table[CHANNELMSG_COUNT]; 370 381 371 382 ··· 392 403 void vmbus_on_event(unsigned long data); 393 404 void vmbus_on_msg_dpc(unsigned long data); 394 405 395 - int hv_kvp_init(struct hv_util_service *); 406 + int hv_kvp_init(struct hv_util_service *srv); 396 407 void hv_kvp_deinit(void); 397 - void hv_kvp_onchannelcallback(void *); 408 + void hv_kvp_onchannelcallback(void *context); 398 409 399 - int hv_vss_init(struct hv_util_service *); 410 + int hv_vss_init(struct hv_util_service *srv); 400 411 void hv_vss_deinit(void); 401 - void hv_vss_onchannelcallback(void *); 412 + void hv_vss_onchannelcallback(void *context); 402 413 403 - int hv_fcopy_init(struct hv_util_service *); 414 + int hv_fcopy_init(struct hv_util_service *srv); 404 415 void hv_fcopy_deinit(void); 405 - void hv_fcopy_onchannelcallback(void *); 416 + void hv_fcopy_onchannelcallback(void *context); 406 417 void vmbus_initiate_unload(bool crash); 407 418 408 419 static inline void hv_poll_channel(struct vmbus_channel *channel,
+8 -14
drivers/hv/ring_buffer.c
··· 75 75 */ 76 76 if (old_write == READ_ONCE(rbi->ring_buffer->read_index)) 77 77 vmbus_setevent(channel); 78 - 79 - return; 80 78 } 81 79 82 80 /* Get the next write location for the specified ring buffer. */ ··· 208 210 ring_info->ring_buffer->interrupt_mask; 209 211 } 210 212 } 213 + EXPORT_SYMBOL_GPL(hv_ringbuffer_get_debuginfo); 211 214 212 215 /* Initialize the ring buffer. */ 213 216 int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ··· 268 269 int hv_ringbuffer_write(struct vmbus_channel *channel, 269 270 const struct kvec *kv_list, u32 kv_count) 270 271 { 271 - int i = 0; 272 + int i; 272 273 u32 bytes_avail_towrite; 273 - u32 totalbytes_towrite = 0; 274 - 274 + u32 totalbytes_towrite = sizeof(u64); 275 275 u32 next_write_location; 276 276 u32 old_write; 277 - u64 prev_indices = 0; 278 - unsigned long flags = 0; 277 + u64 prev_indices; 278 + unsigned long flags; 279 279 struct hv_ring_buffer_info *outring_info = &channel->outbound; 280 280 281 281 if (channel->rescind) ··· 282 284 283 285 for (i = 0; i < kv_count; i++) 284 286 totalbytes_towrite += kv_list[i].iov_len; 285 - 286 - totalbytes_towrite += sizeof(u64); 287 287 288 288 spin_lock_irqsave(&outring_info->ring_lock, flags); 289 289 ··· 345 349 u64 *requestid, bool raw) 346 350 { 347 351 u32 bytes_avail_toread; 348 - u32 next_read_location = 0; 352 + u32 next_read_location; 349 353 u64 prev_indices = 0; 350 354 struct vmpacket_descriptor desc; 351 355 u32 offset; 352 356 u32 packetlen; 353 - int ret = 0; 354 357 struct hv_ring_buffer_info *inring_info = &channel->inbound; 355 358 356 359 if (buflen <= 0) 357 360 return -EINVAL; 358 - 359 361 360 362 *buffer_actual_len = 0; 361 363 *requestid = 0; ··· 365 371 * No error is set when there is even no header, drivers are 366 372 * supposed to analyze buffer_actual_len. 367 373 */ 368 - return ret; 374 + return 0; 369 375 } 370 376 371 377 init_cached_read_index(inring_info); ··· 411 417 412 418 hv_signal_on_read(channel); 413 419 414 - return ret; 420 + return 0; 415 421 } 416 422 417 423 /*
+1 -3
drivers/hv/vmbus_drv.c
··· 787 787 788 788 if (drv->shutdown) 789 789 drv->shutdown(dev); 790 - 791 - return; 792 790 } 793 791 794 792 ··· 853 855 struct hv_message *msg = (struct hv_message *)page_addr + 854 856 VMBUS_MESSAGE_SINT; 855 857 struct vmbus_channel_message_header *hdr; 856 - struct vmbus_channel_message_table_entry *entry; 858 + const struct vmbus_channel_message_table_entry *entry; 857 859 struct onmessage_work_context *ctx; 858 860 u32 message_type = msg->header.message_type; 859 861
+1 -1
drivers/hwtracing/coresight/of_coresight.c
··· 149 149 continue; 150 150 151 151 /* The local out port number */ 152 - pdata->outports[i] = endpoint.id; 152 + pdata->outports[i] = endpoint.port; 153 153 154 154 /* 155 155 * Get a handle on the remote port and parent
+4 -11
drivers/iio/industrialio-core.c
··· 1719 1719 1720 1720 cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); 1721 1721 indio_dev->chrdev.owner = indio_dev->info->driver_module; 1722 - indio_dev->chrdev.kobj.parent = &indio_dev->dev.kobj; 1723 - ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1); 1722 + 1723 + ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev); 1724 1724 if (ret < 0) 1725 1725 goto error_unreg_eventset; 1726 1726 1727 - ret = device_add(&indio_dev->dev); 1728 - if (ret < 0) 1729 - goto error_cdev_del; 1730 - 1731 1727 return 0; 1732 - error_cdev_del: 1733 - cdev_del(&indio_dev->chrdev); 1728 + 1734 1729 error_unreg_eventset: 1735 1730 iio_device_unregister_eventset(indio_dev); 1736 1731 error_free_sysfs: ··· 1746 1751 { 1747 1752 mutex_lock(&indio_dev->info_exist_lock); 1748 1753 1749 - device_del(&indio_dev->dev); 1754 + cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); 1750 1755 1751 - if (indio_dev->chrdev.dev) 1752 - cdev_del(&indio_dev->chrdev); 1753 1756 iio_device_unregister_debugfs(indio_dev); 1754 1757 1755 1758 iio_disable_all_buffers(indio_dev);
+18 -17
drivers/infiniband/core/ucm.c
··· 1205 1205 struct ib_ucm_device *ucm_dev; 1206 1206 1207 1207 ucm_dev = container_of(dev, struct ib_ucm_device, dev); 1208 - cdev_del(&ucm_dev->cdev); 1208 + kfree(ucm_dev); 1209 + } 1210 + 1211 + static void ib_ucm_free_dev(struct ib_ucm_device *ucm_dev) 1212 + { 1209 1213 if (ucm_dev->devnum < IB_UCM_MAX_DEVICES) 1210 1214 clear_bit(ucm_dev->devnum, dev_map); 1211 1215 else 1212 1216 clear_bit(ucm_dev->devnum - IB_UCM_MAX_DEVICES, overflow_map); 1213 - kfree(ucm_dev); 1214 1217 } 1215 1218 1216 1219 static const struct file_operations ucm_fops = { ··· 1269 1266 if (!ucm_dev) 1270 1267 return; 1271 1268 1269 + device_initialize(&ucm_dev->dev); 1272 1270 ucm_dev->ib_dev = device; 1271 + ucm_dev->dev.release = ib_ucm_release_dev; 1273 1272 1274 1273 devnum = find_first_zero_bit(dev_map, IB_UCM_MAX_DEVICES); 1275 1274 if (devnum >= IB_UCM_MAX_DEVICES) { ··· 1291 1286 cdev_init(&ucm_dev->cdev, &ucm_fops); 1292 1287 ucm_dev->cdev.owner = THIS_MODULE; 1293 1288 kobject_set_name(&ucm_dev->cdev.kobj, "ucm%d", ucm_dev->devnum); 1294 - if (cdev_add(&ucm_dev->cdev, base, 1)) 1295 - goto err; 1296 1289 1297 1290 ucm_dev->dev.class = &cm_class; 1298 1291 ucm_dev->dev.parent = device->dev.parent; 1299 - ucm_dev->dev.devt = ucm_dev->cdev.dev; 1300 - ucm_dev->dev.release = ib_ucm_release_dev; 1292 + ucm_dev->dev.devt = base; 1293 + 1301 1294 dev_set_name(&ucm_dev->dev, "ucm%d", ucm_dev->devnum); 1302 - if (device_register(&ucm_dev->dev)) 1303 - goto err_cdev; 1295 + if (cdev_device_add(&ucm_dev->cdev, &ucm_dev->dev)) 1296 + goto err_devnum; 1304 1297 1305 1298 if (device_create_file(&ucm_dev->dev, &dev_attr_ibdev)) 1306 1299 goto err_dev; ··· 1307 1304 return; 1308 1305 1309 1306 err_dev: 1310 - device_unregister(&ucm_dev->dev); 1311 - err_cdev: 1312 - cdev_del(&ucm_dev->cdev); 1313 - if (ucm_dev->devnum < IB_UCM_MAX_DEVICES) 1314 - clear_bit(devnum, dev_map); 1315 - else 1316 - clear_bit(devnum, overflow_map); 1307 + cdev_device_del(&ucm_dev->cdev, &ucm_dev->dev); 1308 + err_devnum: 1309 + ib_ucm_free_dev(ucm_dev); 1317 1310 err: 1318 - kfree(ucm_dev); 1311 + put_device(&ucm_dev->dev); 1319 1312 return; 1320 1313 } 1321 1314 ··· 1322 1323 if (!ucm_dev) 1323 1324 return; 1324 1325 1325 - device_unregister(&ucm_dev->dev); 1326 + cdev_device_del(&ucm_dev->cdev, &ucm_dev->dev); 1327 + ib_ucm_free_dev(ucm_dev); 1328 + put_device(&ucm_dev->dev); 1326 1329 } 1327 1330 1328 1331 static CLASS_ATTR_STRING(abi_version, S_IRUGO,
+2 -2
drivers/infiniband/core/user_mad.c
··· 1187 1187 1188 1188 cdev_init(&port->cdev, &umad_fops); 1189 1189 port->cdev.owner = THIS_MODULE; 1190 - port->cdev.kobj.parent = &umad_dev->kobj; 1190 + cdev_set_parent(&port->cdev, &umad_dev->kobj); 1191 1191 kobject_set_name(&port->cdev.kobj, "umad%d", port->dev_num); 1192 1192 if (cdev_add(&port->cdev, base, 1)) 1193 1193 goto err_cdev; ··· 1206 1206 base += IB_UMAD_MAX_PORTS; 1207 1207 cdev_init(&port->sm_cdev, &umad_sm_fops); 1208 1208 port->sm_cdev.owner = THIS_MODULE; 1209 - port->sm_cdev.kobj.parent = &umad_dev->kobj; 1209 + cdev_set_parent(&port->sm_cdev, &umad_dev->kobj); 1210 1210 kobject_set_name(&port->sm_cdev.kobj, "issm%d", port->dev_num); 1211 1211 if (cdev_add(&port->sm_cdev, base, 1)) 1212 1212 goto err_sm_cdev;
+1 -1
drivers/infiniband/core/uverbs_main.c
··· 1093 1093 cdev_init(&uverbs_dev->cdev, NULL); 1094 1094 uverbs_dev->cdev.owner = THIS_MODULE; 1095 1095 uverbs_dev->cdev.ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops; 1096 - uverbs_dev->cdev.kobj.parent = &uverbs_dev->kobj; 1096 + cdev_set_parent(&uverbs_dev->cdev, &uverbs_dev->kobj); 1097 1097 kobject_set_name(&uverbs_dev->cdev.kobj, "uverbs%d", uverbs_dev->devnum); 1098 1098 if (cdev_add(&uverbs_dev->cdev, base, 1)) 1099 1099 goto err_cdev;
+1 -1
drivers/infiniband/hw/hfi1/device.c
··· 69 69 70 70 cdev_init(cdev, fops); 71 71 cdev->owner = THIS_MODULE; 72 - cdev->kobj.parent = parent; 72 + cdev_set_parent(cdev, parent); 73 73 kobject_set_name(&cdev->kobj, name); 74 74 75 75 ret = cdev_add(cdev, dev, 1);
+2 -9
drivers/input/evdev.c
··· 1354 1354 evdev_mark_dead(evdev); 1355 1355 evdev_hangup(evdev); 1356 1356 1357 - cdev_del(&evdev->cdev); 1358 - 1359 1357 /* evdev is marked dead so no one else accesses evdev->open */ 1360 1358 if (evdev->open) { 1361 1359 input_flush_device(handle, NULL); ··· 1414 1416 goto err_free_evdev; 1415 1417 1416 1418 cdev_init(&evdev->cdev, &evdev_fops); 1417 - evdev->cdev.kobj.parent = &evdev->dev.kobj; 1418 - error = cdev_add(&evdev->cdev, evdev->dev.devt, 1); 1419 - if (error) 1420 - goto err_unregister_handle; 1421 1419 1422 - error = device_add(&evdev->dev); 1420 + error = cdev_device_add(&evdev->cdev, &evdev->dev); 1423 1421 if (error) 1424 1422 goto err_cleanup_evdev; 1425 1423 ··· 1423 1429 1424 1430 err_cleanup_evdev: 1425 1431 evdev_cleanup(evdev); 1426 - err_unregister_handle: 1427 1432 input_unregister_handle(&evdev->handle); 1428 1433 err_free_evdev: 1429 1434 put_device(&evdev->dev); ··· 1435 1442 { 1436 1443 struct evdev *evdev = handle->private; 1437 1444 1438 - device_del(&evdev->dev); 1445 + cdev_device_del(&evdev->cdev, &evdev->dev); 1439 1446 evdev_cleanup(evdev); 1440 1447 input_free_minor(MINOR(evdev->dev.devt)); 1441 1448 input_unregister_handle(handle);
+2 -9
drivers/input/joydev.c
··· 742 742 joydev_mark_dead(joydev); 743 743 joydev_hangup(joydev); 744 744 745 - cdev_del(&joydev->cdev); 746 - 747 745 /* joydev is marked dead so no one else accesses joydev->open */ 748 746 if (joydev->open) 749 747 input_close_device(handle); ··· 911 913 goto err_free_joydev; 912 914 913 915 cdev_init(&joydev->cdev, &joydev_fops); 914 - joydev->cdev.kobj.parent = &joydev->dev.kobj; 915 - error = cdev_add(&joydev->cdev, joydev->dev.devt, 1); 916 - if (error) 917 - goto err_unregister_handle; 918 916 919 - error = device_add(&joydev->dev); 917 + error = cdev_device_add(&joydev->cdev, &joydev->dev); 920 918 if (error) 921 919 goto err_cleanup_joydev; 922 920 ··· 920 926 921 927 err_cleanup_joydev: 922 928 joydev_cleanup(joydev); 923 - err_unregister_handle: 924 929 input_unregister_handle(&joydev->handle); 925 930 err_free_joydev: 926 931 put_device(&joydev->dev); ··· 932 939 { 933 940 struct joydev *joydev = handle->private; 934 941 935 - device_del(&joydev->dev); 942 + cdev_device_del(&joydev->cdev, &joydev->dev); 936 943 joydev_cleanup(joydev); 937 944 input_free_minor(MINOR(joydev->dev.devt)); 938 945 input_unregister_handle(handle);
+2 -9
drivers/input/mousedev.c
··· 812 812 mousedev_mark_dead(mousedev); 813 813 mousedev_hangup(mousedev); 814 814 815 - cdev_del(&mousedev->cdev); 816 - 817 815 /* mousedev is marked dead so no one else accesses mousedev->open */ 818 816 if (mousedev->open) 819 817 input_close_device(handle); ··· 899 901 } 900 902 901 903 cdev_init(&mousedev->cdev, &mousedev_fops); 902 - mousedev->cdev.kobj.parent = &mousedev->dev.kobj; 903 - error = cdev_add(&mousedev->cdev, mousedev->dev.devt, 1); 904 - if (error) 905 - goto err_unregister_handle; 906 904 907 - error = device_add(&mousedev->dev); 905 + error = cdev_device_add(&mousedev->cdev, &mousedev->dev); 908 906 if (error) 909 907 goto err_cleanup_mousedev; 910 908 ··· 908 914 909 915 err_cleanup_mousedev: 910 916 mousedev_cleanup(mousedev); 911 - err_unregister_handle: 912 917 if (!mixdev) 913 918 input_unregister_handle(&mousedev->handle); 914 919 err_free_mousedev: ··· 920 927 921 928 static void mousedev_destroy(struct mousedev *mousedev) 922 929 { 923 - device_del(&mousedev->dev); 930 + cdev_device_del(&mousedev->cdev, &mousedev->dev); 924 931 mousedev_cleanup(mousedev); 925 932 input_free_minor(MINOR(mousedev->dev.devt)); 926 933 if (mousedev != mousedev_mix)
+4 -12
drivers/media/cec/cec-core.c
··· 137 137 138 138 /* Part 2: Initialize and register the character device */ 139 139 cdev_init(&devnode->cdev, &cec_devnode_fops); 140 - devnode->cdev.kobj.parent = &devnode->dev.kobj; 141 140 devnode->cdev.owner = owner; 142 141 143 - ret = cdev_add(&devnode->cdev, devnode->dev.devt, 1); 144 - if (ret < 0) { 145 - pr_err("%s: cdev_add failed\n", __func__); 142 + ret = cdev_device_add(&devnode->cdev, &devnode->dev); 143 + if (ret) { 144 + pr_err("%s: cdev_device_add failed\n", __func__); 146 145 goto clr_bit; 147 146 } 148 - 149 - ret = device_add(&devnode->dev); 150 - if (ret) 151 - goto cdev_del; 152 147 153 148 devnode->registered = true; 154 149 return 0; 155 150 156 - cdev_del: 157 - cdev_del(&devnode->cdev); 158 151 clr_bit: 159 152 mutex_lock(&cec_devnode_lock); 160 153 clear_bit(devnode->minor, cec_devnode_nums); ··· 183 190 devnode->unregistered = true; 184 191 mutex_unlock(&devnode->lock); 185 192 186 - device_del(&devnode->dev); 187 - cdev_del(&devnode->cdev); 193 + cdev_device_del(&devnode->cdev, &devnode->dev); 188 194 put_device(&devnode->dev); 189 195 } 190 196
+5 -15
drivers/media/media-devnode.c
··· 248 248 dev_set_name(&devnode->dev, "media%d", devnode->minor); 249 249 device_initialize(&devnode->dev); 250 250 251 - /* Part 2: Initialize and register the character device */ 251 + /* Part 2: Initialize the character device */ 252 252 cdev_init(&devnode->cdev, &media_devnode_fops); 253 253 devnode->cdev.owner = owner; 254 - devnode->cdev.kobj.parent = &devnode->dev.kobj; 255 254 256 - ret = cdev_add(&devnode->cdev, MKDEV(MAJOR(media_dev_t), devnode->minor), 1); 255 + /* Part 3: Add the media and char device */ 256 + ret = cdev_device_add(&devnode->cdev, &devnode->dev); 257 257 if (ret < 0) { 258 - pr_err("%s: cdev_add failed\n", __func__); 258 + pr_err("%s: cdev_device_add failed\n", __func__); 259 259 goto cdev_add_error; 260 - } 261 - 262 - /* Part 3: Add the media device */ 263 - ret = device_add(&devnode->dev); 264 - if (ret < 0) { 265 - pr_err("%s: device_add failed\n", __func__); 266 - goto device_add_error; 267 260 } 268 261 269 262 /* Part 4: Activate this minor. The char device can now be used. */ ··· 264 271 265 272 return 0; 266 273 267 - device_add_error: 268 - cdev_del(&devnode->cdev); 269 274 cdev_add_error: 270 275 mutex_lock(&media_devnode_lock); 271 276 clear_bit(devnode->minor, media_devnode_nums); ··· 289 298 { 290 299 mutex_lock(&media_devnode_lock); 291 300 /* Delete the cdev on this minor as well */ 292 - cdev_del(&devnode->cdev); 301 + cdev_device_del(&devnode->cdev, &devnode->dev); 293 302 mutex_unlock(&media_devnode_lock); 294 - device_del(&devnode->dev); 295 303 devnode->media_dev = NULL; 296 304 put_device(&devnode->dev); 297 305 }
+6 -287
drivers/misc/Kconfig
··· 419 419 To compile this driver as a module, choose M here: the 420 420 module will be called vmw_balloon. 421 421 422 - config ARM_CHARLCD 423 - bool "ARM Ltd. Character LCD Driver" 424 - depends on PLAT_VERSATILE 425 - help 426 - This is a driver for the character LCD found on the ARM Ltd. 427 - Versatile and RealView Platform Baseboards. It doesn't do 428 - very much more than display the text "ARM Linux" on the first 429 - line and the Linux version on the second line, but that's 430 - still useful. 431 - 432 422 config PCH_PHUB 433 423 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB" 434 424 select GENERIC_NET_UTILS ··· 482 492 bus. System Configuration interface is one of the possible means 483 493 of generating transactions on this bus. 484 494 485 - config PANEL 486 - tristate "Parallel port LCD/Keypad Panel support" 487 - depends on PARPORT 495 + config ASPEED_LPC_CTRL 496 + depends on (ARCH_ASPEED || COMPILE_TEST) && REGMAP && MFD_SYSCON 497 + tristate "Aspeed ast2400/2500 HOST LPC to BMC bridge control" 488 498 ---help--- 489 - Say Y here if you have an HD44780 or KS-0074 LCD connected to your 490 - parallel port. This driver also features 4 and 6-key keypads. The LCD 491 - is accessible through the /dev/lcd char device (10, 156), and the 492 - keypad through /dev/keypad (10, 185). This code can either be 493 - compiled as a module, or linked into the kernel and started at boot. 494 - If you don't understand what all this is about, say N. 495 - 496 - if PANEL 497 - 498 - config PANEL_PARPORT 499 - int "Default parallel port number (0=LPT1)" 500 - range 0 255 501 - default "0" 502 - ---help--- 503 - This is the index of the parallel port the panel is connected to. One 504 - driver instance only supports one parallel port, so if your keypad 505 - and LCD are connected to two separate ports, you have to start two 506 - modules with different arguments. Numbering starts with '0' for LPT1, 507 - and so on. 508 - 509 - config PANEL_PROFILE 510 - int "Default panel profile (0-5, 0=custom)" 511 - range 0 5 512 - default "5" 513 - ---help--- 514 - To ease configuration, the driver supports different configuration 515 - profiles for past and recent wirings. These profiles can also be 516 - used to define an approximative configuration, completed by a few 517 - other options. Here are the profiles : 518 - 519 - 0 = custom (see further) 520 - 1 = 2x16 parallel LCD, old keypad 521 - 2 = 2x16 serial LCD (KS-0074), new keypad 522 - 3 = 2x16 parallel LCD (Hantronix), no keypad 523 - 4 = 2x16 parallel LCD (Nexcom NSA1045) with Nexcom's keypad 524 - 5 = 2x40 parallel LCD (old one), with old keypad 525 - 526 - Custom configurations allow you to define how your display is 527 - wired to the parallel port, and how it works. This is only intended 528 - for experts. 529 - 530 - config PANEL_KEYPAD 531 - depends on PANEL_PROFILE="0" 532 - int "Keypad type (0=none, 1=old 6 keys, 2=new 6 keys, 3=Nexcom 4 keys)" 533 - range 0 3 534 - default 0 535 - ---help--- 536 - This enables and configures a keypad connected to the parallel port. 537 - The keys will be read from character device 10,185. Valid values are : 538 - 539 - 0 : do not enable this driver 540 - 1 : old 6 keys keypad 541 - 2 : new 6 keys keypad, as used on the server at www.ant-computing.com 542 - 3 : Nexcom NSA1045's 4 keys keypad 543 - 544 - New profiles can be described in the driver source. The driver also 545 - supports simultaneous keys pressed when the keypad supports them. 546 - 547 - config PANEL_LCD 548 - depends on PANEL_PROFILE="0" 549 - int "LCD type (0=none, 1=custom, 2=old //, 3=ks0074, 4=hantronix, 5=Nexcom)" 550 - range 0 5 551 - default 0 552 - ---help--- 553 - This enables and configures an LCD connected to the parallel port. 554 - The driver includes an interpreter for escape codes starting with 555 - '\e[L' which are specific to the LCD, and a few ANSI codes. The 556 - driver will be registered as character device 10,156, usually 557 - under the name '/dev/lcd'. There are a total of 6 supported types : 558 - 559 - 0 : do not enable the driver 560 - 1 : custom configuration and wiring (see further) 561 - 2 : 2x16 & 2x40 parallel LCD (old wiring) 562 - 3 : 2x16 serial LCD (KS-0074 based) 563 - 4 : 2x16 parallel LCD (Hantronix wiring) 564 - 5 : 2x16 parallel LCD (Nexcom wiring) 565 - 566 - When type '1' is specified, other options will appear to configure 567 - more precise aspects (wiring, dimensions, protocol, ...). Please note 568 - that those values changed from the 2.4 driver for better consistency. 569 - 570 - config PANEL_LCD_HEIGHT 571 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 572 - int "Number of lines on the LCD (1-2)" 573 - range 1 2 574 - default 2 575 - ---help--- 576 - This is the number of visible character lines on the LCD in custom profile. 577 - It can either be 1 or 2. 578 - 579 - config PANEL_LCD_WIDTH 580 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 581 - int "Number of characters per line on the LCD (1-40)" 582 - range 1 40 583 - default 40 584 - ---help--- 585 - This is the number of characters per line on the LCD in custom profile. 586 - Common values are 16,20,24,40. 587 - 588 - config PANEL_LCD_BWIDTH 589 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 590 - int "Internal LCD line width (1-40, 40 by default)" 591 - range 1 40 592 - default 40 593 - ---help--- 594 - Most LCDs use a standard controller which supports hardware lines of 40 595 - characters, although sometimes only 16, 20 or 24 of them are really wired 596 - to the terminal. This results in some non-visible but addressable characters, 597 - and is the case for most parallel LCDs. Other LCDs, and some serial ones, 598 - however, use the same line width internally as what is visible. The KS0074 599 - for example, uses 16 characters per line for 16 visible characters per line. 600 - 601 - This option lets you configure the value used by your LCD in 'custom' profile. 602 - If you don't know, put '40' here. 603 - 604 - config PANEL_LCD_HWIDTH 605 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 606 - int "Hardware LCD line width (1-64, 64 by default)" 607 - range 1 64 608 - default 64 609 - ---help--- 610 - Most LCDs use a single address bit to differentiate line 0 and line 1. Since 611 - some of them need to be able to address 40 chars with the lower bits, they 612 - often use the immediately superior power of 2, which is 64, to address the 613 - next line. 614 - 615 - If you don't know what your LCD uses, in doubt let 16 here for a 2x16, and 616 - 64 here for a 2x40. 617 - 618 - config PANEL_LCD_CHARSET 619 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 620 - int "LCD character set (0=normal, 1=KS0074)" 621 - range 0 1 622 - default 0 623 - ---help--- 624 - Some controllers such as the KS0074 use a somewhat strange character set 625 - where many symbols are at unusual places. The driver knows how to map 626 - 'standard' ASCII characters to the character sets used by these controllers. 627 - Valid values are : 628 - 629 - 0 : normal (untranslated) character set 630 - 1 : KS0074 character set 631 - 632 - If you don't know, use the normal one (0). 633 - 634 - config PANEL_LCD_PROTO 635 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 636 - int "LCD communication mode (0=parallel 8 bits, 1=serial)" 637 - range 0 1 638 - default 0 639 - ---help--- 640 - This driver now supports any serial or parallel LCD wired to a parallel 641 - port. But before assigning signals, the driver needs to know if it will 642 - be driving a serial LCD or a parallel one. Serial LCDs only use 2 wires 643 - (SDA/SCL), while parallel ones use 2 or 3 wires for the control signals 644 - (E, RS, sometimes RW), and 4 or 8 for the data. Use 0 here for a 8 bits 645 - parallel LCD, and 1 for a serial LCD. 646 - 647 - config PANEL_LCD_PIN_E 648 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 649 - int "Parallel port pin number & polarity connected to the LCD E signal (-17...17) " 650 - range -17 17 651 - default 14 652 - ---help--- 653 - This describes the number of the parallel port pin to which the LCD 'E' 654 - signal has been connected. It can be : 655 - 656 - 0 : no connection (eg: connected to ground) 657 - 1..17 : directly connected to any of these pins on the DB25 plug 658 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 659 - 660 - Default for the 'E' pin in custom profile is '14' (AUTOFEED). 661 - 662 - config PANEL_LCD_PIN_RS 663 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 664 - int "Parallel port pin number & polarity connected to the LCD RS signal (-17...17) " 665 - range -17 17 666 - default 17 667 - ---help--- 668 - This describes the number of the parallel port pin to which the LCD 'RS' 669 - signal has been connected. It can be : 670 - 671 - 0 : no connection (eg: connected to ground) 672 - 1..17 : directly connected to any of these pins on the DB25 plug 673 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 674 - 675 - Default for the 'RS' pin in custom profile is '17' (SELECT IN). 676 - 677 - config PANEL_LCD_PIN_RW 678 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO="0" 679 - int "Parallel port pin number & polarity connected to the LCD RW signal (-17...17) " 680 - range -17 17 681 - default 16 682 - ---help--- 683 - This describes the number of the parallel port pin to which the LCD 'RW' 684 - signal has been connected. It can be : 685 - 686 - 0 : no connection (eg: connected to ground) 687 - 1..17 : directly connected to any of these pins on the DB25 plug 688 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 689 - 690 - Default for the 'RW' pin in custom profile is '16' (INIT). 691 - 692 - config PANEL_LCD_PIN_SCL 693 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO!="0" 694 - int "Parallel port pin number & polarity connected to the LCD SCL signal (-17...17) " 695 - range -17 17 696 - default 1 697 - ---help--- 698 - This describes the number of the parallel port pin to which the serial 699 - LCD 'SCL' signal has been connected. It can be : 700 - 701 - 0 : no connection (eg: connected to ground) 702 - 1..17 : directly connected to any of these pins on the DB25 plug 703 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 704 - 705 - Default for the 'SCL' pin in custom profile is '1' (STROBE). 706 - 707 - config PANEL_LCD_PIN_SDA 708 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" && PANEL_LCD_PROTO!="0" 709 - int "Parallel port pin number & polarity connected to the LCD SDA signal (-17...17) " 710 - range -17 17 711 - default 2 712 - ---help--- 713 - This describes the number of the parallel port pin to which the serial 714 - LCD 'SDA' signal has been connected. It can be : 715 - 716 - 0 : no connection (eg: connected to ground) 717 - 1..17 : directly connected to any of these pins on the DB25 plug 718 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 719 - 720 - Default for the 'SDA' pin in custom profile is '2' (D0). 721 - 722 - config PANEL_LCD_PIN_BL 723 - depends on PANEL_PROFILE="0" && PANEL_LCD="1" 724 - int "Parallel port pin number & polarity connected to the LCD backlight signal (-17...17) " 725 - range -17 17 726 - default 0 727 - ---help--- 728 - This describes the number of the parallel port pin to which the LCD 'BL' signal 729 - has been connected. It can be : 730 - 731 - 0 : no connection (eg: connected to ground) 732 - 1..17 : directly connected to any of these pins on the DB25 plug 733 - -1..-17 : connected to the same pin through an inverter (eg: transistor). 734 - 735 - Default for the 'BL' pin in custom profile is '0' (uncontrolled). 736 - 737 - config PANEL_CHANGE_MESSAGE 738 - bool "Change LCD initialization message ?" 739 - default "n" 740 - ---help--- 741 - This allows you to replace the boot message indicating the kernel version 742 - and the driver version with a custom message. This is useful on appliances 743 - where a simple 'Starting system' message can be enough to stop a customer 744 - from worrying. 745 - 746 - If you say 'Y' here, you'll be able to choose a message yourself. Otherwise, 747 - say 'N' and keep the default message with the version. 748 - 749 - config PANEL_BOOT_MESSAGE 750 - depends on PANEL_CHANGE_MESSAGE="y" 751 - string "New initialization message" 752 - default "" 753 - ---help--- 754 - This allows you to replace the boot message indicating the kernel version 755 - and the driver version with a custom message. This is useful on appliances 756 - where a simple 'Starting system' message can be enough to stop a customer 757 - from worrying. 758 - 759 - An empty message will only clear the display at driver init time. Any other 760 - printf()-formatted message is valid with newline and escape codes. 761 - 762 - endif # PANEL 499 + Control Aspeed ast2400/2500 HOST LPC to BMC mappings through 500 + ioctl()s, the driver also provides a read/write interface to a BMC ram 501 + region where the host LPC read/write region can be buffered. 763 502 764 503 source "drivers/misc/c2port/Kconfig" 765 504 source "drivers/misc/eeprom/Kconfig"
+3 -2
drivers/misc/Makefile
··· 37 37 obj-y += cb710/ 38 38 obj-$(CONFIG_SPEAR13XX_PCIE_GADGET) += spear13xx_pcie_gadget.o 39 39 obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o 40 - obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o 41 40 obj-$(CONFIG_PCH_PHUB) += pch_phub.o 42 41 obj-y += ti-st/ 43 42 obj-y += lis3lv02d/ ··· 52 53 obj-$(CONFIG_ECHO) += echo/ 53 54 obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o 54 55 obj-$(CONFIG_CXL_BASE) += cxl/ 55 - obj-$(CONFIG_PANEL) += panel.o 56 + obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o 56 57 57 58 lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o 58 59 lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o ··· 60 61 lkdtm-$(CONFIG_LKDTM) += lkdtm_perms.o 61 62 lkdtm-$(CONFIG_LKDTM) += lkdtm_rodata_objcopy.o 62 63 lkdtm-$(CONFIG_LKDTM) += lkdtm_usercopy.o 64 + 65 + KCOV_INSTRUMENT_lkdtm_rodata.o := n 63 66 64 67 OBJCOPYFLAGS := 65 68 OBJCOPYFLAGS_lkdtm_rodata_objcopy.o := \
drivers/misc/arm-charlcd.c drivers/auxdisplay/arm-charlcd.c
+266
drivers/misc/aspeed-lpc-ctrl.c
··· 1 + /* 2 + * Copyright 2017 IBM Corporation 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * as published by the Free Software Foundation; either version 7 + * 2 of the License, or (at your option) any later version. 8 + */ 9 + 10 + #include <linux/mfd/syscon.h> 11 + #include <linux/miscdevice.h> 12 + #include <linux/mm.h> 13 + #include <linux/module.h> 14 + #include <linux/of_address.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/poll.h> 17 + #include <linux/regmap.h> 18 + 19 + #include <linux/aspeed-lpc-ctrl.h> 20 + 21 + #define DEVICE_NAME "aspeed-lpc-ctrl" 22 + 23 + #define HICR7 0x8 24 + #define HICR8 0xc 25 + 26 + struct aspeed_lpc_ctrl { 27 + struct miscdevice miscdev; 28 + struct regmap *regmap; 29 + phys_addr_t mem_base; 30 + resource_size_t mem_size; 31 + u32 pnor_size; 32 + u32 pnor_base; 33 + }; 34 + 35 + static struct aspeed_lpc_ctrl *file_aspeed_lpc_ctrl(struct file *file) 36 + { 37 + return container_of(file->private_data, struct aspeed_lpc_ctrl, 38 + miscdev); 39 + } 40 + 41 + static int aspeed_lpc_ctrl_mmap(struct file *file, struct vm_area_struct *vma) 42 + { 43 + struct aspeed_lpc_ctrl *lpc_ctrl = file_aspeed_lpc_ctrl(file); 44 + unsigned long vsize = vma->vm_end - vma->vm_start; 45 + pgprot_t prot = vma->vm_page_prot; 46 + 47 + if (vma->vm_pgoff + vsize > lpc_ctrl->mem_base + lpc_ctrl->mem_size) 48 + return -EINVAL; 49 + 50 + /* ast2400/2500 AHB accesses are not cache coherent */ 51 + prot = pgprot_noncached(prot); 52 + 53 + if (remap_pfn_range(vma, vma->vm_start, 54 + (lpc_ctrl->mem_base >> PAGE_SHIFT) + vma->vm_pgoff, 55 + vsize, prot)) 56 + return -EAGAIN; 57 + 58 + return 0; 59 + } 60 + 61 + static long aspeed_lpc_ctrl_ioctl(struct file *file, unsigned int cmd, 62 + unsigned long param) 63 + { 64 + struct aspeed_lpc_ctrl *lpc_ctrl = file_aspeed_lpc_ctrl(file); 65 + void __user *p = (void __user *)param; 66 + struct aspeed_lpc_ctrl_mapping map; 67 + u32 addr; 68 + u32 size; 69 + long rc; 70 + 71 + if (copy_from_user(&map, p, sizeof(map))) 72 + return -EFAULT; 73 + 74 + if (map.flags != 0) 75 + return -EINVAL; 76 + 77 + switch (cmd) { 78 + case ASPEED_LPC_CTRL_IOCTL_GET_SIZE: 79 + /* The flash windows don't report their size */ 80 + if (map.window_type != ASPEED_LPC_CTRL_WINDOW_MEMORY) 81 + return -EINVAL; 82 + 83 + /* Support more than one window id in the future */ 84 + if (map.window_id != 0) 85 + return -EINVAL; 86 + 87 + map.size = lpc_ctrl->mem_size; 88 + 89 + return copy_to_user(p, &map, sizeof(map)) ? -EFAULT : 0; 90 + case ASPEED_LPC_CTRL_IOCTL_MAP: 91 + 92 + /* 93 + * The top half of HICR7 is the MSB of the BMC address of the 94 + * mapping. 95 + * The bottom half of HICR7 is the MSB of the HOST LPC 96 + * firmware space address of the mapping. 97 + * 98 + * The 1 bits in the top of half of HICR8 represent the bits 99 + * (in the requested address) that should be ignored and 100 + * replaced with those from the top half of HICR7. 101 + * The 1 bits in the bottom half of HICR8 represent the bits 102 + * (in the requested address) that should be kept and pass 103 + * into the BMC address space. 104 + */ 105 + 106 + /* 107 + * It doesn't make sense to talk about a size or offset with 108 + * low 16 bits set. Both HICR7 and HICR8 talk about the top 16 109 + * bits of addresses and sizes. 110 + */ 111 + 112 + if ((map.size & 0x0000ffff) || (map.offset & 0x0000ffff)) 113 + return -EINVAL; 114 + 115 + /* 116 + * Because of the way the masks work in HICR8 offset has to 117 + * be a multiple of size. 118 + */ 119 + if (map.offset & (map.size - 1)) 120 + return -EINVAL; 121 + 122 + if (map.window_type == ASPEED_LPC_CTRL_WINDOW_FLASH) { 123 + addr = lpc_ctrl->pnor_base; 124 + size = lpc_ctrl->pnor_size; 125 + } else if (map.window_type == ASPEED_LPC_CTRL_WINDOW_MEMORY) { 126 + addr = lpc_ctrl->mem_base; 127 + size = lpc_ctrl->mem_size; 128 + } else { 129 + return -EINVAL; 130 + } 131 + 132 + /* Check overflow first! */ 133 + if (map.offset + map.size < map.offset || 134 + map.offset + map.size > size) 135 + return -EINVAL; 136 + 137 + if (map.size == 0 || map.size > size) 138 + return -EINVAL; 139 + 140 + addr += map.offset; 141 + 142 + /* 143 + * addr (host lpc address) is safe regardless of values. This 144 + * simply changes the address the host has to request on its 145 + * side of the LPC bus. This cannot impact the hosts own 146 + * memory space by surprise as LPC specific accessors are 147 + * required. The only strange thing that could be done is 148 + * setting the lower 16 bits but the shift takes care of that. 149 + */ 150 + 151 + rc = regmap_write(lpc_ctrl->regmap, HICR7, 152 + (addr | (map.addr >> 16))); 153 + if (rc) 154 + return rc; 155 + 156 + return regmap_write(lpc_ctrl->regmap, HICR8, 157 + (~(map.size - 1)) | ((map.size >> 16) - 1)); 158 + } 159 + 160 + return -EINVAL; 161 + } 162 + 163 + static const struct file_operations aspeed_lpc_ctrl_fops = { 164 + .owner = THIS_MODULE, 165 + .mmap = aspeed_lpc_ctrl_mmap, 166 + .unlocked_ioctl = aspeed_lpc_ctrl_ioctl, 167 + }; 168 + 169 + static int aspeed_lpc_ctrl_probe(struct platform_device *pdev) 170 + { 171 + struct aspeed_lpc_ctrl *lpc_ctrl; 172 + struct device_node *node; 173 + struct resource resm; 174 + struct device *dev; 175 + int rc; 176 + 177 + dev = &pdev->dev; 178 + 179 + lpc_ctrl = devm_kzalloc(dev, sizeof(*lpc_ctrl), GFP_KERNEL); 180 + if (!lpc_ctrl) 181 + return -ENOMEM; 182 + 183 + node = of_parse_phandle(dev->of_node, "flash", 0); 184 + if (!node) { 185 + dev_err(dev, "Didn't find host pnor flash node\n"); 186 + return -ENODEV; 187 + } 188 + 189 + rc = of_address_to_resource(node, 1, &resm); 190 + of_node_put(node); 191 + if (rc) { 192 + dev_err(dev, "Couldn't address to resource for flash\n"); 193 + return rc; 194 + } 195 + 196 + lpc_ctrl->pnor_size = resource_size(&resm); 197 + lpc_ctrl->pnor_base = resm.start; 198 + 199 + dev_set_drvdata(&pdev->dev, lpc_ctrl); 200 + 201 + node = of_parse_phandle(dev->of_node, "memory-region", 0); 202 + if (!node) { 203 + dev_err(dev, "Didn't find reserved memory\n"); 204 + return -EINVAL; 205 + } 206 + 207 + rc = of_address_to_resource(node, 0, &resm); 208 + of_node_put(node); 209 + if (rc) { 210 + dev_err(dev, "Couldn't address to resource for reserved memory\n"); 211 + return -ENOMEM; 212 + } 213 + 214 + lpc_ctrl->mem_size = resource_size(&resm); 215 + lpc_ctrl->mem_base = resm.start; 216 + 217 + lpc_ctrl->regmap = syscon_node_to_regmap( 218 + pdev->dev.parent->of_node); 219 + if (IS_ERR(lpc_ctrl->regmap)) { 220 + dev_err(dev, "Couldn't get regmap\n"); 221 + return -ENODEV; 222 + } 223 + 224 + lpc_ctrl->miscdev.minor = MISC_DYNAMIC_MINOR; 225 + lpc_ctrl->miscdev.name = DEVICE_NAME; 226 + lpc_ctrl->miscdev.fops = &aspeed_lpc_ctrl_fops; 227 + lpc_ctrl->miscdev.parent = dev; 228 + rc = misc_register(&lpc_ctrl->miscdev); 229 + if (rc) 230 + dev_err(dev, "Unable to register device\n"); 231 + else 232 + dev_info(dev, "Loaded at %pr\n", &resm); 233 + 234 + return rc; 235 + } 236 + 237 + static int aspeed_lpc_ctrl_remove(struct platform_device *pdev) 238 + { 239 + struct aspeed_lpc_ctrl *lpc_ctrl = dev_get_drvdata(&pdev->dev); 240 + 241 + misc_deregister(&lpc_ctrl->miscdev); 242 + 243 + return 0; 244 + } 245 + 246 + static const struct of_device_id aspeed_lpc_ctrl_match[] = { 247 + { .compatible = "aspeed,ast2400-lpc-ctrl" }, 248 + { .compatible = "aspeed,ast2500-lpc-ctrl" }, 249 + { }, 250 + }; 251 + 252 + static struct platform_driver aspeed_lpc_ctrl_driver = { 253 + .driver = { 254 + .name = DEVICE_NAME, 255 + .of_match_table = aspeed_lpc_ctrl_match, 256 + }, 257 + .probe = aspeed_lpc_ctrl_probe, 258 + .remove = aspeed_lpc_ctrl_remove, 259 + }; 260 + 261 + module_platform_driver(aspeed_lpc_ctrl_driver); 262 + 263 + MODULE_DEVICE_TABLE(of, aspeed_lpc_ctrl_match); 264 + MODULE_LICENSE("GPL"); 265 + MODULE_AUTHOR("Cyril Bur <cyrilbur@gmail.com>"); 266 + MODULE_DESCRIPTION("Control for aspeed 2400/2500 LPC HOST to BMC mappings");
+7
drivers/misc/ds1682.c
··· 227 227 }; 228 228 MODULE_DEVICE_TABLE(i2c, ds1682_id); 229 229 230 + static const struct of_device_id ds1682_of_match[] = { 231 + { .compatible = "dallas,ds1682", }, 232 + {} 233 + }; 234 + MODULE_DEVICE_TABLE(of, ds1682_of_match); 235 + 230 236 static struct i2c_driver ds1682_driver = { 231 237 .driver = { 232 238 .name = "ds1682", 239 + .of_match_table = ds1682_of_match, 233 240 }, 234 241 .probe = ds1682_probe, 235 242 .remove = ds1682_remove,
+57
drivers/misc/eeprom/idt_89hpesx.c
··· 1541 1541 }; 1542 1542 MODULE_DEVICE_TABLE(i2c, idt_ids); 1543 1543 1544 + static const struct of_device_id idt_of_match[] = { 1545 + { .compatible = "idt,89hpes8nt2", }, 1546 + { .compatible = "idt,89hpes12nt3", }, 1547 + 1548 + { .compatible = "idt,89hpes24nt6ag2", }, 1549 + { .compatible = "idt,89hpes32nt8ag2", }, 1550 + { .compatible = "idt,89hpes32nt8bg2", }, 1551 + { .compatible = "idt,89hpes12nt12g2", }, 1552 + { .compatible = "idt,89hpes16nt16g2", }, 1553 + { .compatible = "idt,89hpes24nt24g2", }, 1554 + { .compatible = "idt,89hpes32nt24ag2", }, 1555 + { .compatible = "idt,89hpes32nt24bg2", }, 1556 + 1557 + { .compatible = "idt,89hpes12n3", }, 1558 + { .compatible = "idt,89hpes12n3a", }, 1559 + { .compatible = "idt,89hpes24n3", }, 1560 + { .compatible = "idt,89hpes24n3a", }, 1561 + 1562 + { .compatible = "idt,89hpes32h8", }, 1563 + { .compatible = "idt,89hpes32h8g2", }, 1564 + { .compatible = "idt,89hpes48h12", }, 1565 + { .compatible = "idt,89hpes48h12g2", }, 1566 + { .compatible = "idt,89hpes48h12ag2", }, 1567 + { .compatible = "idt,89hpes16h16", }, 1568 + { .compatible = "idt,89hpes22h16", }, 1569 + { .compatible = "idt,89hpes22h16g2", }, 1570 + { .compatible = "idt,89hpes34h16", }, 1571 + { .compatible = "idt,89hpes34h16g2", }, 1572 + { .compatible = "idt,89hpes64h16", }, 1573 + { .compatible = "idt,89hpes64h16g2", }, 1574 + { .compatible = "idt,89hpes64h16ag2", }, 1575 + 1576 + { .compatible = "idt,89hpes12t3g2", }, 1577 + { .compatible = "idt,89hpes24t3g2", }, 1578 + 1579 + { .compatible = "idt,89hpes16t4", }, 1580 + { .compatible = "idt,89hpes4t4g2", }, 1581 + { .compatible = "idt,89hpes10t4g2", }, 1582 + { .compatible = "idt,89hpes16t4g2", }, 1583 + { .compatible = "idt,89hpes16t4ag2", }, 1584 + { .compatible = "idt,89hpes5t5", }, 1585 + { .compatible = "idt,89hpes6t5", }, 1586 + { .compatible = "idt,89hpes8t5", }, 1587 + { .compatible = "idt,89hpes8t5a", }, 1588 + { .compatible = "idt,89hpes24t6", }, 1589 + { .compatible = "idt,89hpes6t6g2", }, 1590 + { .compatible = "idt,89hpes24t6g2", }, 1591 + { .compatible = "idt,89hpes16t7", }, 1592 + { .compatible = "idt,89hpes32t8", }, 1593 + { .compatible = "idt,89hpes32t8g2", }, 1594 + { .compatible = "idt,89hpes48t12", }, 1595 + { .compatible = "idt,89hpes48t12g2", }, 1596 + { }, 1597 + }; 1598 + MODULE_DEVICE_TABLE(of, idt_of_match); 1599 + 1544 1600 /* 1545 1601 * idt_driver - IDT 89HPESx driver structure 1546 1602 */ 1547 1603 static struct i2c_driver idt_driver = { 1548 1604 .driver = { 1549 1605 .name = IDT_NAME, 1606 + .of_match_table = idt_of_match, 1550 1607 }, 1551 1608 .probe = idt_probe, 1552 1609 .remove = idt_remove,
+1
drivers/misc/lkdtm.h
··· 27 27 void lkdtm_REFCOUNT_ZERO_ADD(void); 28 28 void lkdtm_CORRUPT_LIST_ADD(void); 29 29 void lkdtm_CORRUPT_LIST_DEL(void); 30 + void lkdtm_CORRUPT_USER_DS(void); 30 31 31 32 /* lkdtm_heap.c */ 32 33 void lkdtm_OVERWRITE_ALLOCATION(void);
+12 -1
drivers/misc/lkdtm_bugs.c
··· 8 8 #include <linux/list.h> 9 9 #include <linux/refcount.h> 10 10 #include <linux/sched.h> 11 + #include <linux/sched/signal.h> 12 + #include <linux/uaccess.h> 11 13 12 14 struct lkdtm_list { 13 15 struct list_head node; ··· 69 67 70 68 void lkdtm_EXCEPTION(void) 71 69 { 72 - *((int *) 0) = 0; 70 + *((volatile int *) 0) = 0; 73 71 } 74 72 75 73 void lkdtm_LOOP(void) ··· 280 278 pr_err("Overwrite did not happen, but no BUG?!\n"); 281 279 else 282 280 pr_err("list_del() corruption not detected!\n"); 281 + } 282 + 283 + void lkdtm_CORRUPT_USER_DS(void) 284 + { 285 + pr_info("setting bad task size limit\n"); 286 + set_fs(KERNEL_DS); 287 + 288 + /* Make sure we do not keep running with a KERNEL_DS! */ 289 + force_sig(SIGKILL, current); 283 290 }
+1
drivers/misc/lkdtm_core.c
··· 199 199 CRASHTYPE(OVERFLOW), 200 200 CRASHTYPE(CORRUPT_LIST_ADD), 201 201 CRASHTYPE(CORRUPT_LIST_DEL), 202 + CRASHTYPE(CORRUPT_USER_DS), 202 203 CRASHTYPE(CORRUPT_STACK), 203 204 CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE), 204 205 CRASHTYPE(OVERWRITE_ALLOCATION),
-1
drivers/misc/mei/Makefile
··· 8 8 mei-objs += interrupt.o 9 9 mei-objs += client.o 10 10 mei-objs += main.o 11 - mei-objs += amthif.o 12 11 mei-objs += bus.o 13 12 mei-objs += bus-fixup.o 14 13 mei-$(CONFIG_DEBUG_FS) += debugfs.o
-340
drivers/misc/mei/amthif.c
··· 1 - /* 2 - * 3 - * Intel Management Engine Interface (Intel MEI) Linux driver 4 - * Copyright (c) 2003-2012, Intel Corporation. 5 - * 6 - * This program is free software; you can redistribute it and/or modify it 7 - * under the terms and conditions of the GNU General Public License, 8 - * version 2, as published by the Free Software Foundation. 9 - * 10 - * This program is distributed in the hope it will be useful, but WITHOUT 11 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 - * more details. 14 - * 15 - */ 16 - 17 - #include <linux/kernel.h> 18 - #include <linux/fs.h> 19 - #include <linux/errno.h> 20 - #include <linux/types.h> 21 - #include <linux/fcntl.h> 22 - #include <linux/ioctl.h> 23 - #include <linux/cdev.h> 24 - #include <linux/list.h> 25 - #include <linux/delay.h> 26 - #include <linux/sched.h> 27 - #include <linux/uuid.h> 28 - #include <linux/jiffies.h> 29 - #include <linux/uaccess.h> 30 - #include <linux/slab.h> 31 - 32 - #include <linux/mei.h> 33 - 34 - #include "mei_dev.h" 35 - #include "hbm.h" 36 - #include "client.h" 37 - 38 - const uuid_le mei_amthif_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 39 - 0xac, 0xa8, 0x46, 0xe0, 40 - 0xff, 0x65, 0x81, 0x4c); 41 - 42 - /** 43 - * mei_amthif_reset_params - initializes mei device iamthif 44 - * 45 - * @dev: the device structure 46 - */ 47 - void mei_amthif_reset_params(struct mei_device *dev) 48 - { 49 - /* reset iamthif parameters. */ 50 - dev->iamthif_canceled = false; 51 - dev->iamthif_state = MEI_IAMTHIF_IDLE; 52 - dev->iamthif_stall_timer = 0; 53 - dev->iamthif_open_count = 0; 54 - } 55 - 56 - /** 57 - * mei_amthif_host_init - mei initialization amthif client. 58 - * 59 - * @dev: the device structure 60 - * @me_cl: me client 61 - * 62 - * Return: 0 on success, <0 on failure. 63 - */ 64 - int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl) 65 - { 66 - struct mei_cl *cl = &dev->iamthif_cl; 67 - int ret; 68 - 69 - mutex_lock(&dev->device_lock); 70 - 71 - if (mei_cl_is_connected(cl)) { 72 - ret = 0; 73 - goto out; 74 - } 75 - 76 - dev->iamthif_state = MEI_IAMTHIF_IDLE; 77 - 78 - mei_cl_init(cl, dev); 79 - 80 - ret = mei_cl_link(cl); 81 - if (ret < 0) { 82 - dev_err(dev->dev, "amthif: failed cl_link %d\n", ret); 83 - goto out; 84 - } 85 - 86 - ret = mei_cl_connect(cl, me_cl, NULL); 87 - 88 - out: 89 - mutex_unlock(&dev->device_lock); 90 - return ret; 91 - } 92 - 93 - /** 94 - * mei_amthif_read_start - queue message for sending read credential 95 - * 96 - * @cl: host client 97 - * @fp: file pointer of message recipient 98 - * 99 - * Return: 0 on success, <0 on failure. 100 - */ 101 - static int mei_amthif_read_start(struct mei_cl *cl, const struct file *fp) 102 - { 103 - struct mei_device *dev = cl->dev; 104 - struct mei_cl_cb *cb; 105 - 106 - cb = mei_cl_enqueue_ctrl_wr_cb(cl, mei_cl_mtu(cl), MEI_FOP_READ, fp); 107 - if (!cb) 108 - return -ENOMEM; 109 - 110 - cl->rx_flow_ctrl_creds++; 111 - 112 - dev->iamthif_state = MEI_IAMTHIF_READING; 113 - cl->fp = cb->fp; 114 - 115 - return 0; 116 - } 117 - 118 - /** 119 - * mei_amthif_run_next_cmd - send next amt command from queue 120 - * 121 - * @dev: the device structure 122 - * 123 - * Return: 0 on success, <0 on failure. 124 - */ 125 - int mei_amthif_run_next_cmd(struct mei_device *dev) 126 - { 127 - struct mei_cl *cl = &dev->iamthif_cl; 128 - struct mei_cl_cb *cb; 129 - int ret; 130 - 131 - dev->iamthif_canceled = false; 132 - 133 - dev_dbg(dev->dev, "complete amthif cmd_list cb.\n"); 134 - 135 - cb = list_first_entry_or_null(&dev->amthif_cmd_list, typeof(*cb), list); 136 - if (!cb) { 137 - dev->iamthif_state = MEI_IAMTHIF_IDLE; 138 - cl->fp = NULL; 139 - return 0; 140 - } 141 - 142 - list_del_init(&cb->list); 143 - dev->iamthif_state = MEI_IAMTHIF_WRITING; 144 - cl->fp = cb->fp; 145 - 146 - ret = mei_cl_write(cl, cb); 147 - if (ret < 0) 148 - return ret; 149 - 150 - if (cb->completed) 151 - cb->status = mei_amthif_read_start(cl, cb->fp); 152 - 153 - return 0; 154 - } 155 - 156 - /** 157 - * mei_amthif_write - write amthif data to amthif client 158 - * 159 - * @cl: host client 160 - * @cb: mei call back struct 161 - * 162 - * Return: 0 on success, <0 on failure. 163 - */ 164 - int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) 165 - { 166 - 167 - struct mei_device *dev = cl->dev; 168 - 169 - list_add_tail(&cb->list, &dev->amthif_cmd_list); 170 - 171 - /* 172 - * The previous request is still in processing, queue this one. 173 - */ 174 - if (dev->iamthif_state != MEI_IAMTHIF_IDLE) 175 - return 0; 176 - 177 - return mei_amthif_run_next_cmd(dev); 178 - } 179 - 180 - /** 181 - * mei_amthif_poll - the amthif poll function 182 - * 183 - * @file: pointer to file structure 184 - * @wait: pointer to poll_table structure 185 - * 186 - * Return: poll mask 187 - * 188 - * Locking: called under "dev->device_lock" lock 189 - */ 190 - unsigned int mei_amthif_poll(struct file *file, poll_table *wait) 191 - { 192 - struct mei_cl *cl = file->private_data; 193 - struct mei_cl_cb *cb = mei_cl_read_cb(cl, file); 194 - unsigned int mask = 0; 195 - 196 - poll_wait(file, &cl->rx_wait, wait); 197 - if (cb) 198 - mask |= POLLIN | POLLRDNORM; 199 - 200 - return mask; 201 - } 202 - 203 - /** 204 - * mei_amthif_irq_write - write iamthif command in irq thread context. 205 - * 206 - * @cl: private data of the file object. 207 - * @cb: callback block. 208 - * @cmpl_list: complete list. 209 - * 210 - * Return: 0, OK; otherwise, error. 211 - */ 212 - int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 213 - struct list_head *cmpl_list) 214 - { 215 - int ret; 216 - 217 - ret = mei_cl_irq_write(cl, cb, cmpl_list); 218 - if (ret) 219 - return ret; 220 - 221 - if (cb->completed) 222 - cb->status = mei_amthif_read_start(cl, cb->fp); 223 - 224 - return 0; 225 - } 226 - 227 - /** 228 - * mei_amthif_irq_read_msg - read routine after ISR to 229 - * handle the read amthif message 230 - * 231 - * @cl: mei client 232 - * @mei_hdr: header of amthif message 233 - * @cmpl_list: completed callbacks list 234 - * 235 - * Return: -ENODEV if cb is NULL 0 otherwise; error message is in cb->status 236 - */ 237 - int mei_amthif_irq_read_msg(struct mei_cl *cl, 238 - struct mei_msg_hdr *mei_hdr, 239 - struct list_head *cmpl_list) 240 - { 241 - struct mei_device *dev; 242 - int ret; 243 - 244 - dev = cl->dev; 245 - 246 - if (dev->iamthif_state != MEI_IAMTHIF_READING) { 247 - mei_irq_discard_msg(dev, mei_hdr); 248 - return 0; 249 - } 250 - 251 - ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); 252 - if (ret) 253 - return ret; 254 - 255 - if (!mei_hdr->msg_complete) 256 - return 0; 257 - 258 - dev_dbg(dev->dev, "completed amthif read.\n "); 259 - dev->iamthif_stall_timer = 0; 260 - 261 - return 0; 262 - } 263 - 264 - /** 265 - * mei_amthif_complete - complete amthif callback. 266 - * 267 - * @cl: host client 268 - * @cb: callback block. 269 - */ 270 - void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb) 271 - { 272 - struct mei_device *dev = cl->dev; 273 - 274 - dev_dbg(dev->dev, "completing amthif call back.\n"); 275 - switch (cb->fop_type) { 276 - case MEI_FOP_WRITE: 277 - if (!cb->status) { 278 - dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; 279 - mei_schedule_stall_timer(dev); 280 - mei_io_cb_free(cb); 281 - return; 282 - } 283 - dev->iamthif_state = MEI_IAMTHIF_IDLE; 284 - cl->fp = NULL; 285 - if (!dev->iamthif_canceled) { 286 - /* 287 - * in case of error enqueue the write cb to complete 288 - * read list so it can be propagated to the reader 289 - */ 290 - list_add_tail(&cb->list, &cl->rd_completed); 291 - wake_up_interruptible(&cl->rx_wait); 292 - } else { 293 - mei_io_cb_free(cb); 294 - } 295 - break; 296 - case MEI_FOP_READ: 297 - if (!dev->iamthif_canceled) { 298 - list_add_tail(&cb->list, &cl->rd_completed); 299 - dev_dbg(dev->dev, "amthif read completed\n"); 300 - wake_up_interruptible(&cl->rx_wait); 301 - } else { 302 - mei_io_cb_free(cb); 303 - } 304 - 305 - dev->iamthif_stall_timer = 0; 306 - mei_amthif_run_next_cmd(dev); 307 - break; 308 - default: 309 - WARN_ON(1); 310 - } 311 - } 312 - 313 - /** 314 - * mei_amthif_release - the release function 315 - * 316 - * @dev: device structure 317 - * @fp: pointer to file structure 318 - * 319 - * Return: 0 on success, <0 on error 320 - */ 321 - int mei_amthif_release(struct mei_device *dev, struct file *fp) 322 - { 323 - struct mei_cl *cl = fp->private_data; 324 - 325 - if (dev->iamthif_open_count > 0) 326 - dev->iamthif_open_count--; 327 - 328 - if (cl->fp == fp && dev->iamthif_state != MEI_IAMTHIF_IDLE) { 329 - 330 - dev_dbg(dev->dev, "amthif canceled iamthif state %d\n", 331 - dev->iamthif_state); 332 - dev->iamthif_canceled = true; 333 - } 334 - 335 - /* Don't clean ctrl_rd_list here, the reads has to be completed */ 336 - mei_io_list_free_fp(&dev->amthif_cmd_list, fp); 337 - mei_io_list_free_fp(&cl->rd_completed, fp); 338 - 339 - return 0; 340 - }
+5 -4
drivers/misc/mei/bus-fixup.c
··· 110 110 u8 data[0]; 111 111 } __packed; 112 112 113 + #define MKHI_OSVER_BUF_LEN (sizeof(struct mkhi_msg_hdr) + \ 114 + sizeof(struct mkhi_fwcaps) + \ 115 + sizeof(struct mei_os_ver)) 113 116 static int mei_osver(struct mei_cl_device *cldev) 114 117 { 115 - const size_t size = sizeof(struct mkhi_msg_hdr) + 116 - sizeof(struct mkhi_fwcaps) + 117 - sizeof(struct mei_os_ver); 118 - char buf[size]; 118 + const size_t size = MKHI_OSVER_BUF_LEN; 119 + char buf[MKHI_OSVER_BUF_LEN]; 119 120 struct mkhi_msg *req; 120 121 struct mkhi_fwcaps *fwcaps; 121 122 struct mei_os_ver *os_ver;
-6
drivers/misc/mei/bus.c
··· 1076 1076 { 1077 1077 struct mei_device *bus = 1078 1078 container_of(work, struct mei_device, bus_rescan_work); 1079 - struct mei_me_client *me_cl; 1080 - 1081 - me_cl = mei_me_cl_by_uuid(bus, &mei_amthif_guid); 1082 - if (me_cl) 1083 - mei_amthif_host_init(bus, me_cl); 1084 - mei_me_cl_put(me_cl); 1085 1079 1086 1080 mei_cl_bus_rescan(bus); 1087 1081 }
+5 -9
drivers/misc/mei/client.c
··· 428 428 * @head: io list 429 429 * @fp: file pointer (matching cb file object), may be NULL 430 430 */ 431 - void mei_io_list_free_fp(struct list_head *head, const struct file *fp) 431 + static void mei_io_list_free_fp(struct list_head *head, const struct file *fp) 432 432 { 433 433 struct mei_cl_cb *cb, *next; 434 434 ··· 554 554 * @cl: host client to be initialized 555 555 * @dev: mei device 556 556 */ 557 - void mei_cl_init(struct mei_cl *cl, struct mei_device *dev) 557 + static void mei_cl_init(struct mei_cl *cl, struct mei_device *dev) 558 558 { 559 559 memset(cl, 0, sizeof(struct mei_cl)); 560 560 init_waitqueue_head(&cl->wait); ··· 600 600 int mei_cl_link(struct mei_cl *cl) 601 601 { 602 602 struct mei_device *dev; 603 - long open_handle_count; 604 603 int id; 605 604 606 605 if (WARN_ON(!cl || !cl->dev)) ··· 613 614 return -EMFILE; 614 615 } 615 616 616 - open_handle_count = dev->open_handle_count + dev->iamthif_open_count; 617 - if (open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { 617 + if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { 618 618 dev_err(dev->dev, "open_handle_count exceeded %d", 619 619 MEI_MAX_OPEN_HANDLE_COUNT); 620 620 return -EMFILE; ··· 647 649 if (!cl) 648 650 return 0; 649 651 650 - /* amthif might not be initialized */ 651 - if (!cl->dev) 652 + if (WARN_ON(!cl->dev)) 652 653 return 0; 653 654 654 655 dev = cl->dev; ··· 760 763 mei_io_list_free_cl(&dev->write_waiting_list, cl); 761 764 mei_io_list_flush_cl(&dev->ctrl_rd_list, cl); 762 765 mei_io_list_flush_cl(&dev->ctrl_wr_list, cl); 763 - mei_io_list_free_cl(&dev->amthif_cmd_list, cl); 764 766 mei_cl_wake_all(cl); 765 767 cl->rx_flow_ctrl_creds = 0; 766 768 cl->tx_flow_ctrl_creds = 0; ··· 1474 1478 return -ENOTTY; 1475 1479 } 1476 1480 1477 - if (mei_cl_is_fixed_address(cl) || cl == &dev->iamthif_cl) 1481 + if (mei_cl_is_fixed_address(cl)) 1478 1482 return 0; 1479 1483 1480 1484 /* HW currently supports only one pending read */
-5
drivers/misc/mei/client.h
··· 83 83 * MEI IO Functions 84 84 */ 85 85 void mei_io_cb_free(struct mei_cl_cb *priv_cb); 86 - void mei_io_list_free_fp(struct list_head *head, const struct file *fp); 87 86 88 87 /* 89 88 * MEI Host Client Functions 90 89 */ 91 90 92 91 struct mei_cl *mei_cl_allocate(struct mei_device *dev); 93 - void mei_cl_init(struct mei_cl *cl, struct mei_device *dev); 94 - 95 92 96 93 int mei_cl_link(struct mei_cl *cl); 97 94 int mei_cl_unlink(struct mei_cl *cl); ··· 202 205 int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, 203 206 struct list_head *cmpl_list); 204 207 int mei_cl_read_start(struct mei_cl *cl, size_t length, const struct file *fp); 205 - int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr, 206 - struct list_head *cmpl_list); 207 208 int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb); 208 209 int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 209 210 struct list_head *cmpl_list);
+14 -15
drivers/misc/mei/hbm.c
··· 166 166 * 167 167 * Return: 0 on success, <0 on failure. 168 168 */ 169 - static inline 170 - int mei_hbm_cl_write(struct mei_device *dev, struct mei_cl *cl, 171 - u8 hbm_cmd, u8 *buf, size_t len) 169 + static inline int mei_hbm_cl_write(struct mei_device *dev, struct mei_cl *cl, 170 + u8 hbm_cmd, void *buf, size_t len) 172 171 { 173 172 struct mei_msg_hdr mei_hdr; 174 173 ··· 631 632 */ 632 633 int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl) 633 634 { 634 - const size_t len = sizeof(struct hbm_flow_control); 635 - u8 buf[len]; 635 + struct hbm_flow_control req; 636 636 637 637 cl_dbg(dev, cl, "sending flow control\n"); 638 - return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, buf, len); 638 + return mei_hbm_cl_write(dev, cl, MEI_FLOW_CONTROL_CMD, 639 + &req, sizeof(req)); 639 640 } 640 641 641 642 /** ··· 709 710 */ 710 711 int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) 711 712 { 712 - const size_t len = sizeof(struct hbm_client_connect_request); 713 - u8 buf[len]; 713 + struct hbm_client_connect_request req; 714 714 715 - return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, buf, len); 715 + return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_REQ_CMD, 716 + &req, sizeof(req)); 716 717 } 717 718 718 719 /** ··· 725 726 */ 726 727 int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) 727 728 { 728 - const size_t len = sizeof(struct hbm_client_connect_response); 729 - u8 buf[len]; 729 + struct hbm_client_connect_response resp; 730 730 731 - return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, buf, len); 731 + return mei_hbm_cl_write(dev, cl, CLIENT_DISCONNECT_RES_CMD, 732 + &resp, sizeof(resp)); 732 733 } 733 734 734 735 /** ··· 762 763 */ 763 764 int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) 764 765 { 765 - const size_t len = sizeof(struct hbm_client_connect_request); 766 - u8 buf[len]; 766 + struct hbm_client_connect_request req; 767 767 768 - return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, buf, len); 768 + return mei_hbm_cl_write(dev, cl, CLIENT_CONNECT_REQ_CMD, 769 + &req, sizeof(req)); 769 770 } 770 771 771 772 /**
+1 -13
drivers/misc/mei/init.c
··· 146 146 /* fall through and remove the sw state even if hw reset has failed */ 147 147 148 148 /* no need to clean up software state in case of power up */ 149 - if (state != MEI_DEV_INITIALIZING && 150 - state != MEI_DEV_POWER_UP) { 151 - 152 - /* remove all waiting requests */ 149 + if (state != MEI_DEV_INITIALIZING && state != MEI_DEV_POWER_UP) 153 150 mei_cl_all_disconnect(dev); 154 - 155 - /* remove entry if already in list */ 156 - dev_dbg(dev->dev, "remove iamthif from the file list.\n"); 157 - mei_cl_unlink(&dev->iamthif_cl); 158 - mei_amthif_reset_params(dev); 159 - } 160 151 161 152 mei_hbm_reset(dev); 162 153 ··· 391 400 INIT_DELAYED_WORK(&dev->timer_work, mei_timer); 392 401 INIT_WORK(&dev->reset_work, mei_reset_work); 393 402 INIT_WORK(&dev->bus_rescan_work, mei_cl_bus_rescan_work); 394 - 395 - INIT_LIST_HEAD(&dev->iamthif_cl.link); 396 - INIT_LIST_HEAD(&dev->amthif_cmd_list); 397 403 398 404 bitmap_zero(dev->host_clients_map, MEI_CLIENTS_MAX); 399 405 dev->open_handle_count = 0;
+7 -31
drivers/misc/mei/interrupt.c
··· 47 47 list_del_init(&cb->list); 48 48 49 49 dev_dbg(dev->dev, "completing call back.\n"); 50 - if (cl == &dev->iamthif_cl) 51 - mei_amthif_complete(cl, cb); 52 - else 53 - mei_cl_complete(cl, cb); 50 + mei_cl_complete(cl, cb); 54 51 } 55 52 } 56 53 EXPORT_SYMBOL_GPL(mei_irq_compl_handler); ··· 73 76 * @dev: mei device 74 77 * @hdr: message header 75 78 */ 76 - void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr) 79 + static void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr) 77 80 { 78 81 /* 79 82 * no need to check for size as it is guarantied ··· 93 96 * 94 97 * Return: always 0 95 98 */ 96 - int mei_cl_irq_read_msg(struct mei_cl *cl, 97 - struct mei_msg_hdr *mei_hdr, 98 - struct list_head *cmpl_list) 99 + static int mei_cl_irq_read_msg(struct mei_cl *cl, 100 + struct mei_msg_hdr *mei_hdr, 101 + struct list_head *cmpl_list) 99 102 { 100 103 struct mei_device *dev = cl->dev; 101 104 struct mei_cl_cb *cb; ··· 310 313 goto end; 311 314 } 312 315 313 - if (cl == &dev->iamthif_cl) { 314 - ret = mei_amthif_irq_read_msg(cl, mei_hdr, cmpl_list); 315 - } else { 316 - ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); 317 - } 316 + ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); 318 317 319 318 320 319 reset_slots: ··· 416 423 dev_dbg(dev->dev, "complete write list cb.\n"); 417 424 list_for_each_entry_safe(cb, next, &dev->write_list, list) { 418 425 cl = cb->cl; 419 - if (cl == &dev->iamthif_cl) 420 - ret = mei_amthif_irq_write(cl, cb, cmpl_list); 421 - else 422 - ret = mei_cl_irq_write(cl, cb, cmpl_list); 426 + ret = mei_cl_irq_write(cl, cb, cmpl_list); 423 427 if (ret) 424 428 return ret; 425 429 } ··· 500 510 } 501 511 reschedule_timer = true; 502 512 } 503 - } 504 - 505 - if (!mei_cl_is_connected(&dev->iamthif_cl)) 506 - goto out; 507 - 508 - if (dev->iamthif_stall_timer) { 509 - if (--dev->iamthif_stall_timer == 0) { 510 - dev_err(dev->dev, "timer: amthif hanged.\n"); 511 - mei_reset(dev); 512 - 513 - mei_amthif_run_next_cmd(dev); 514 - goto out; 515 - } 516 - reschedule_timer = true; 517 513 } 518 514 519 515 out:
+74 -51
drivers/misc/mei/main.c
··· 103 103 dev = cl->dev; 104 104 105 105 mutex_lock(&dev->device_lock); 106 - if (cl == &dev->iamthif_cl) { 107 - rets = mei_amthif_release(dev, file); 108 - goto out; 109 - } 106 + 110 107 rets = mei_cl_disconnect(cl); 111 108 112 109 mei_cl_flush_queues(cl, file); ··· 114 117 file->private_data = NULL; 115 118 116 119 kfree(cl); 117 - out: 120 + 118 121 mutex_unlock(&dev->device_lock); 119 122 return rets; 120 123 } ··· 179 182 goto out; 180 183 } 181 184 182 - 183 - again: 184 185 mutex_unlock(&dev->device_lock); 185 186 if (wait_event_interruptible(cl->rx_wait, 186 187 !list_empty(&cl->rd_completed) || ··· 196 201 197 202 cb = mei_cl_read_cb(cl, file); 198 203 if (!cb) { 199 - /* 200 - * For amthif all the waiters are woken up, 201 - * but only fp with matching cb->fp get the cb, 202 - * the others have to return to wait on read. 203 - */ 204 - if (cl == &dev->iamthif_cl) 205 - goto again; 206 - 207 204 rets = 0; 208 205 goto out; 209 206 } ··· 306 319 goto out; 307 320 } 308 321 309 - if (cl == &dev->iamthif_cl) { 310 - rets = mei_amthif_write(cl, cb); 311 - if (!rets) 312 - rets = length; 313 - goto out; 314 - } 315 - 316 322 rets = mei_cl_write(cl, cb); 317 323 out: 318 324 mutex_unlock(&dev->device_lock); ··· 367 387 me_cl->props.protocol_version); 368 388 dev_dbg(dev->dev, "FW Client - Max Msg Len = %d\n", 369 389 me_cl->props.max_msg_length); 370 - 371 - /* if we're connecting to amthif client then we will use the 372 - * existing connection 373 - */ 374 - if (uuid_le_cmp(data->in_client_uuid, mei_amthif_guid) == 0) { 375 - dev_dbg(dev->dev, "FW Client is amthi\n"); 376 - if (!mei_cl_is_connected(&dev->iamthif_cl)) { 377 - rets = -ENODEV; 378 - goto end; 379 - } 380 - mei_cl_unlink(cl); 381 - 382 - kfree(cl); 383 - cl = NULL; 384 - dev->iamthif_open_count++; 385 - file->private_data = &dev->iamthif_cl; 386 - 387 - client = &data->out_client_properties; 388 - client->max_msg_length = me_cl->props.max_msg_length; 389 - client->protocol_version = me_cl->props.protocol_version; 390 - rets = dev->iamthif_cl.status; 391 - 392 - goto end; 393 - } 394 390 395 391 /* prepare the output buffer */ 396 392 client = &data->out_client_properties; ··· 571 615 mask |= POLLPRI; 572 616 } 573 617 574 - if (cl == &dev->iamthif_cl) { 575 - mask |= mei_amthif_poll(file, wait); 576 - goto out; 577 - } 578 - 579 618 if (req_events & (POLLIN | POLLRDNORM)) { 580 619 poll_wait(file, &cl->rx_wait, wait); 581 620 ··· 583 632 out: 584 633 mutex_unlock(&dev->device_lock); 585 634 return mask; 635 + } 636 + 637 + /** 638 + * mei_cl_is_write_queued - check if the client has pending writes. 639 + * 640 + * @cl: writing host client 641 + * 642 + * Return: true if client is writing, false otherwise. 643 + */ 644 + static bool mei_cl_is_write_queued(struct mei_cl *cl) 645 + { 646 + struct mei_device *dev = cl->dev; 647 + struct mei_cl_cb *cb; 648 + 649 + list_for_each_entry(cb, &dev->write_list, list) 650 + if (cb->cl == cl) 651 + return true; 652 + list_for_each_entry(cb, &dev->write_waiting_list, list) 653 + if (cb->cl == cl) 654 + return true; 655 + return false; 656 + } 657 + 658 + /** 659 + * mei_fsync - the fsync handler 660 + * 661 + * @fp: pointer to file structure 662 + * @start: unused 663 + * @end: unused 664 + * @datasync: unused 665 + * 666 + * Return: 0 on success, -ENODEV if client is not connected 667 + */ 668 + static int mei_fsync(struct file *fp, loff_t start, loff_t end, int datasync) 669 + { 670 + struct mei_cl *cl = fp->private_data; 671 + struct mei_device *dev; 672 + int rets; 673 + 674 + if (WARN_ON(!cl || !cl->dev)) 675 + return -ENODEV; 676 + 677 + dev = cl->dev; 678 + 679 + mutex_lock(&dev->device_lock); 680 + 681 + if (dev->dev_state != MEI_DEV_ENABLED || !mei_cl_is_connected(cl)) { 682 + rets = -ENODEV; 683 + goto out; 684 + } 685 + 686 + while (mei_cl_is_write_queued(cl)) { 687 + mutex_unlock(&dev->device_lock); 688 + rets = wait_event_interruptible(cl->tx_wait, 689 + cl->writing_state == MEI_WRITE_COMPLETE || 690 + !mei_cl_is_connected(cl)); 691 + mutex_lock(&dev->device_lock); 692 + if (rets) { 693 + if (signal_pending(current)) 694 + rets = -EINTR; 695 + goto out; 696 + } 697 + if (!mei_cl_is_connected(cl)) { 698 + rets = -ENODEV; 699 + goto out; 700 + } 701 + } 702 + rets = 0; 703 + out: 704 + mutex_unlock(&dev->device_lock); 705 + return rets; 586 706 } 587 707 588 708 /** ··· 771 749 .release = mei_release, 772 750 .write = mei_write, 773 751 .poll = mei_poll, 752 + .fsync = mei_fsync, 774 753 .fasync = mei_fasync, 775 754 .llseek = no_llseek 776 755 };
-51
drivers/misc/mei/mei_dev.h
··· 26 26 #include "hw.h" 27 27 #include "hbm.h" 28 28 29 - 30 - /* 31 - * AMTHI Client UUID 32 - */ 33 - extern const uuid_le mei_amthif_guid; 34 - 35 29 #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) 36 30 37 31 /* ··· 71 77 }; 72 78 73 79 const char *mei_dev_state_str(int state); 74 - 75 - enum iamthif_states { 76 - MEI_IAMTHIF_IDLE, 77 - MEI_IAMTHIF_WRITING, 78 - MEI_IAMTHIF_READING, 79 - }; 80 80 81 81 enum mei_file_transaction_states { 82 82 MEI_IDLE, ··· 406 418 * @allow_fixed_address: allow user space to connect a fixed client 407 419 * @override_fixed_address: force allow fixed address behavior 408 420 * 409 - * @amthif_cmd_list : amthif list for cmd waiting 410 - * @iamthif_cl : amthif host client 411 - * @iamthif_open_count : number of opened amthif connections 412 - * @iamthif_stall_timer : timer to detect amthif hang 413 - * @iamthif_state : amthif processor state 414 - * @iamthif_canceled : current amthif command is canceled 415 - * 416 421 * @reset_work : work item for the device reset 417 422 * @bus_rescan_work : work item for the bus rescan 418 423 * ··· 481 500 bool allow_fixed_address; 482 501 bool override_fixed_address; 483 502 484 - /* amthif list for cmd waiting */ 485 - struct list_head amthif_cmd_list; 486 - struct mei_cl iamthif_cl; 487 - long iamthif_open_count; 488 - u32 iamthif_stall_timer; 489 - enum iamthif_states iamthif_state; 490 - bool iamthif_canceled; 491 - 492 503 struct work_struct reset_work; 493 504 struct work_struct bus_rescan_work; 494 505 ··· 550 577 551 578 int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list); 552 579 void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list); 553 - 554 - /* 555 - * AMTHIF - AMT Host Interface Functions 556 - */ 557 - void mei_amthif_reset_params(struct mei_device *dev); 558 - 559 - int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl); 560 - 561 - unsigned int mei_amthif_poll(struct file *file, poll_table *wait); 562 - 563 - int mei_amthif_release(struct mei_device *dev, struct file *file); 564 - 565 - int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); 566 - int mei_amthif_run_next_cmd(struct mei_device *dev); 567 - int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 568 - struct list_head *cmpl_list); 569 - 570 - void mei_amthif_complete(struct mei_cl *cl, struct mei_cl_cb *cb); 571 - int mei_amthif_irq_read_msg(struct mei_cl *cl, 572 - struct mei_msg_hdr *mei_hdr, 573 - struct list_head *cmpl_list); 574 - int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); 575 580 576 581 /* 577 582 * Register Access Function ··· 661 710 bool mei_hbuf_acquire(struct mei_device *dev); 662 711 663 712 bool mei_write_is_idle(struct mei_device *dev); 664 - 665 - void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr); 666 713 667 714 #if IS_ENABLED(CONFIG_DEBUG_FS) 668 715 int mei_dbgfs_register(struct mei_device *dev, const char *name);
+29 -2
drivers/misc/mei/pci-me.c
··· 242 242 } 243 243 244 244 /** 245 + * mei_me_shutdown - Device Removal Routine 246 + * 247 + * @pdev: PCI device structure 248 + * 249 + * mei_me_shutdown is called from the reboot notifier 250 + * it's a simplified version of remove so we go down 251 + * faster. 252 + */ 253 + static void mei_me_shutdown(struct pci_dev *pdev) 254 + { 255 + struct mei_device *dev; 256 + 257 + dev = pci_get_drvdata(pdev); 258 + if (!dev) 259 + return; 260 + 261 + dev_dbg(&pdev->dev, "shutdown\n"); 262 + mei_stop(dev); 263 + 264 + if (!pci_dev_run_wake(pdev)) 265 + mei_me_unset_pm_domain(dev); 266 + 267 + mei_disable_interrupts(dev); 268 + free_irq(pdev->irq, dev); 269 + } 270 + 271 + /** 245 272 * mei_me_remove - Device Removal Routine 246 273 * 247 274 * @pdev: PCI device structure 248 275 * 249 - * mei_remove is called by the PCI subsystem to alert the driver 276 + * mei_me_remove is called by the PCI subsystem to alert the driver 250 277 * that it should release a PCI device. 251 278 */ 252 279 static void mei_me_remove(struct pci_dev *pdev) ··· 483 456 .id_table = mei_me_pci_tbl, 484 457 .probe = mei_me_probe, 485 458 .remove = mei_me_remove, 486 - .shutdown = mei_me_remove, 459 + .shutdown = mei_me_shutdown, 487 460 .driver.pm = MEI_ME_PM_OPS, 488 461 }; 489 462
+28 -1
drivers/misc/mei/pci-txe.c
··· 161 161 } 162 162 163 163 /** 164 + * mei_txe_remove - Device Shutdown Routine 165 + * 166 + * @pdev: PCI device structure 167 + * 168 + * mei_txe_shutdown is called from the reboot notifier 169 + * it's a simplified version of remove so we go down 170 + * faster. 171 + */ 172 + static void mei_txe_shutdown(struct pci_dev *pdev) 173 + { 174 + struct mei_device *dev; 175 + 176 + dev = pci_get_drvdata(pdev); 177 + if (!dev) 178 + return; 179 + 180 + dev_dbg(&pdev->dev, "shutdown\n"); 181 + mei_stop(dev); 182 + 183 + if (!pci_dev_run_wake(pdev)) 184 + mei_txe_unset_pm_domain(dev); 185 + 186 + mei_disable_interrupts(dev); 187 + free_irq(pdev->irq, dev); 188 + } 189 + 190 + /** 164 191 * mei_txe_remove - Device Removal Routine 165 192 * 166 193 * @pdev: PCI device structure ··· 413 386 .id_table = mei_txe_pci_tbl, 414 387 .probe = mei_txe_probe, 415 388 .remove = mei_txe_remove, 416 - .shutdown = mei_txe_remove, 389 + .shutdown = mei_txe_shutdown, 417 390 .driver.pm = MEI_TXE_PM_OPS, 418 391 }; 419 392
+93 -736
drivers/misc/panel.c drivers/auxdisplay/panel.c
··· 1 1 /* 2 2 * Front panel driver for Linux 3 3 * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> 4 + * Copyright (C) 2016-2017 Glider bvba 4 5 * 5 6 * This program is free software; you can redistribute it and/or 6 7 * modify it under the terms of the GNU General Public License ··· 55 54 #include <linux/ctype.h> 56 55 #include <linux/parport.h> 57 56 #include <linux/list.h> 58 - #include <linux/notifier.h> 59 - #include <linux/reboot.h> 60 - #include <linux/workqueue.h> 61 - #include <generated/utsrelease.h> 62 57 63 58 #include <linux/io.h> 64 59 #include <linux/uaccess.h> 65 60 66 - #define LCD_MINOR 156 61 + #include <misc/charlcd.h> 62 + 67 63 #define KEYPAD_MINOR 185 68 64 69 65 #define LCD_MAXBYTES 256 /* max burst write */ ··· 73 75 #define KEYPAD_REP_START (10) 74 76 /* a key repeats this times INPUT_POLL_TIME */ 75 77 #define KEYPAD_REP_DELAY (2) 76 - 77 - /* keep the light on this many seconds for each flash */ 78 - #define FLASH_LIGHT_TEMPO (4) 79 78 80 79 /* converts an r_str() input to an active high, bits string : 000BAOSE */ 81 80 #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3) ··· 114 119 #define PIN_INITP 16 115 120 #define PIN_SELECP 17 116 121 #define PIN_NOT_SET 127 117 - 118 - #define LCD_FLAG_B 0x0004 /* blink on */ 119 - #define LCD_FLAG_C 0x0008 /* cursor on */ 120 - #define LCD_FLAG_D 0x0010 /* display on */ 121 - #define LCD_FLAG_F 0x0020 /* large font mode */ 122 - #define LCD_FLAG_N 0x0040 /* 2-rows mode */ 123 - #define LCD_FLAG_L 0x0080 /* backlight enabled */ 124 - 125 - /* LCD commands */ 126 - #define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */ 127 - 128 - #define LCD_CMD_ENTRY_MODE 0x04 /* Set entry mode */ 129 - #define LCD_CMD_CURSOR_INC 0x02 /* Increment cursor */ 130 - 131 - #define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */ 132 - #define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */ 133 - #define LCD_CMD_CURSOR_ON 0x02 /* Set cursor on */ 134 - #define LCD_CMD_BLINK_ON 0x01 /* Set blink on */ 135 - 136 - #define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */ 137 - #define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */ 138 - #define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */ 139 - 140 - #define LCD_CMD_FUNCTION_SET 0x20 /* Set function */ 141 - #define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */ 142 - #define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */ 143 - #define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */ 144 - 145 - #define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */ 146 - 147 - #define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */ 148 - 149 - #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */ 150 - #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */ 151 122 152 123 #define NOT_SET -1 153 124 ··· 206 245 static struct { 207 246 bool enabled; 208 247 bool initialized; 209 - bool must_clear; 210 248 211 - int height; 212 - int width; 213 - int bwidth; 214 - int hwidth; 215 249 int charset; 216 250 int proto; 217 - 218 - struct delayed_work bl_work; 219 - struct mutex bl_tempo_lock; /* Protects access to bl_tempo */ 220 - bool bl_tempo; 221 251 222 252 /* TODO: use union here? */ 223 253 struct { ··· 220 268 int bl; 221 269 } pins; 222 270 223 - /* contains the LCD config state */ 224 - unsigned long int flags; 225 - 226 - /* Contains the LCD X and Y offset */ 227 - struct { 228 - unsigned long int x; 229 - unsigned long int y; 230 - } addr; 231 - 232 - /* Current escape sequence and it's length or -1 if outside */ 233 - struct { 234 - char buf[LCD_ESCAPE_LEN + 1]; 235 - int len; 236 - } esc_seq; 271 + struct charlcd *charlcd; 237 272 } lcd; 238 273 239 274 /* Needed only for init */ ··· 403 464 /* global variables */ 404 465 405 466 /* Device single-open policy control */ 406 - static atomic_t lcd_available = ATOMIC_INIT(1); 407 467 static atomic_t keypad_available = ATOMIC_INIT(1); 408 468 409 469 static struct pardevice *pprt; 410 470 411 471 static int keypad_initialized; 412 - 413 - static void (*lcd_write_cmd)(int); 414 - static void (*lcd_write_data)(int); 415 - static void (*lcd_clear_fast)(void); 416 472 417 473 static DEFINE_SPINLOCK(pprt_lock); 418 474 static struct timer_list scan_timer; ··· 507 573 static int keypad_enabled = NOT_SET; 508 574 module_param(keypad_enabled, int, 0000); 509 575 MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead"); 510 - 511 - static const unsigned char *lcd_char_conv; 512 576 513 577 /* for some LCD drivers (ks0074) we need a charset conversion table. */ 514 578 static const unsigned char lcd_char_conv_ks0074[256] = { ··· 684 752 } 685 753 } 686 754 687 - /* sleeps that many milliseconds with a reschedule */ 688 - static void long_sleep(int ms) 689 - { 690 - if (in_interrupt()) 691 - mdelay(ms); 692 - else 693 - schedule_timeout_interruptible(msecs_to_jiffies(ms)); 694 - } 695 - 696 755 /* 697 756 * send a serial byte to the LCD panel. The caller is responsible for locking 698 757 * if needed. ··· 715 792 } 716 793 717 794 /* turn the backlight on or off */ 718 - static void __lcd_backlight(int on) 795 + static void lcd_backlight(struct charlcd *charlcd, int on) 719 796 { 797 + if (lcd.pins.bl == PIN_NONE) 798 + return; 799 + 720 800 /* The backlight is activated by setting the AUTOFEED line to +5V */ 721 801 spin_lock_irq(&pprt_lock); 722 802 if (on) ··· 730 804 spin_unlock_irq(&pprt_lock); 731 805 } 732 806 733 - static void lcd_backlight(int on) 734 - { 735 - if (lcd.pins.bl == PIN_NONE) 736 - return; 737 - 738 - mutex_lock(&lcd.bl_tempo_lock); 739 - if (!lcd.bl_tempo) 740 - __lcd_backlight(on); 741 - mutex_unlock(&lcd.bl_tempo_lock); 742 - } 743 - 744 - static void lcd_bl_off(struct work_struct *work) 745 - { 746 - mutex_lock(&lcd.bl_tempo_lock); 747 - if (lcd.bl_tempo) { 748 - lcd.bl_tempo = false; 749 - if (!(lcd.flags & LCD_FLAG_L)) 750 - __lcd_backlight(0); 751 - } 752 - mutex_unlock(&lcd.bl_tempo_lock); 753 - } 754 - 755 - /* turn the backlight on for a little while */ 756 - static void lcd_poke(void) 757 - { 758 - if (lcd.pins.bl == PIN_NONE) 759 - return; 760 - 761 - cancel_delayed_work_sync(&lcd.bl_work); 762 - 763 - mutex_lock(&lcd.bl_tempo_lock); 764 - if (!lcd.bl_tempo && !(lcd.flags & LCD_FLAG_L)) 765 - __lcd_backlight(1); 766 - lcd.bl_tempo = true; 767 - schedule_delayed_work(&lcd.bl_work, FLASH_LIGHT_TEMPO * HZ); 768 - mutex_unlock(&lcd.bl_tempo_lock); 769 - } 770 - 771 807 /* send a command to the LCD panel in serial mode */ 772 - static void lcd_write_cmd_s(int cmd) 808 + static void lcd_write_cmd_s(struct charlcd *charlcd, int cmd) 773 809 { 774 810 spin_lock_irq(&pprt_lock); 775 811 lcd_send_serial(0x1F); /* R/W=W, RS=0 */ ··· 742 854 } 743 855 744 856 /* send data to the LCD panel in serial mode */ 745 - static void lcd_write_data_s(int data) 857 + static void lcd_write_data_s(struct charlcd *charlcd, int data) 746 858 { 747 859 spin_lock_irq(&pprt_lock); 748 860 lcd_send_serial(0x5F); /* R/W=W, RS=1 */ ··· 753 865 } 754 866 755 867 /* send a command to the LCD panel in 8 bits parallel mode */ 756 - static void lcd_write_cmd_p8(int cmd) 868 + static void lcd_write_cmd_p8(struct charlcd *charlcd, int cmd) 757 869 { 758 870 spin_lock_irq(&pprt_lock); 759 871 /* present the data to the data port */ ··· 775 887 } 776 888 777 889 /* send data to the LCD panel in 8 bits parallel mode */ 778 - static void lcd_write_data_p8(int data) 890 + static void lcd_write_data_p8(struct charlcd *charlcd, int data) 779 891 { 780 892 spin_lock_irq(&pprt_lock); 781 893 /* present the data to the data port */ ··· 797 909 } 798 910 799 911 /* send a command to the TI LCD panel */ 800 - static void lcd_write_cmd_tilcd(int cmd) 912 + static void lcd_write_cmd_tilcd(struct charlcd *charlcd, int cmd) 801 913 { 802 914 spin_lock_irq(&pprt_lock); 803 915 /* present the data to the control port */ ··· 807 919 } 808 920 809 921 /* send data to the TI LCD panel */ 810 - static void lcd_write_data_tilcd(int data) 922 + static void lcd_write_data_tilcd(struct charlcd *charlcd, int data) 811 923 { 812 924 spin_lock_irq(&pprt_lock); 813 925 /* present the data to the data port */ ··· 816 928 spin_unlock_irq(&pprt_lock); 817 929 } 818 930 819 - static void lcd_gotoxy(void) 820 - { 821 - lcd_write_cmd(LCD_CMD_SET_DDRAM_ADDR 822 - | (lcd.addr.y ? lcd.hwidth : 0) 823 - /* 824 - * we force the cursor to stay at the end of the 825 - * line if it wants to go farther 826 - */ 827 - | ((lcd.addr.x < lcd.bwidth) ? lcd.addr.x & 828 - (lcd.hwidth - 1) : lcd.bwidth - 1)); 829 - } 830 - 831 - static void lcd_home(void) 832 - { 833 - lcd.addr.x = 0; 834 - lcd.addr.y = 0; 835 - lcd_gotoxy(); 836 - } 837 - 838 - static void lcd_print(char c) 839 - { 840 - if (lcd.addr.x < lcd.bwidth) { 841 - if (lcd_char_conv) 842 - c = lcd_char_conv[(unsigned char)c]; 843 - lcd_write_data(c); 844 - lcd.addr.x++; 845 - } 846 - /* prevents the cursor from wrapping onto the next line */ 847 - if (lcd.addr.x == lcd.bwidth) 848 - lcd_gotoxy(); 849 - } 850 - 851 931 /* fills the display with spaces and resets X/Y */ 852 - static void lcd_clear_fast_s(void) 932 + static void lcd_clear_fast_s(struct charlcd *charlcd) 853 933 { 854 934 int pos; 855 935 856 - lcd_home(); 857 - 858 936 spin_lock_irq(&pprt_lock); 859 - for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) { 937 + for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) { 860 938 lcd_send_serial(0x5F); /* R/W=W, RS=1 */ 861 939 lcd_send_serial(' ' & 0x0F); 862 940 lcd_send_serial((' ' >> 4) & 0x0F); ··· 830 976 udelay(40); 831 977 } 832 978 spin_unlock_irq(&pprt_lock); 833 - 834 - lcd_home(); 835 979 } 836 980 837 981 /* fills the display with spaces and resets X/Y */ 838 - static void lcd_clear_fast_p8(void) 982 + static void lcd_clear_fast_p8(struct charlcd *charlcd) 839 983 { 840 984 int pos; 841 985 842 - lcd_home(); 843 - 844 986 spin_lock_irq(&pprt_lock); 845 - for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) { 987 + for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) { 846 988 /* present the data to the data port */ 847 989 w_dtr(pprt, ' '); 848 990 ··· 860 1010 udelay(45); 861 1011 } 862 1012 spin_unlock_irq(&pprt_lock); 863 - 864 - lcd_home(); 865 1013 } 866 1014 867 1015 /* fills the display with spaces and resets X/Y */ 868 - static void lcd_clear_fast_tilcd(void) 1016 + static void lcd_clear_fast_tilcd(struct charlcd *charlcd) 869 1017 { 870 1018 int pos; 871 1019 872 - lcd_home(); 873 - 874 1020 spin_lock_irq(&pprt_lock); 875 - for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) { 1021 + for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) { 876 1022 /* present the data to the data port */ 877 1023 w_dtr(pprt, ' '); 878 1024 udelay(60); 879 1025 } 880 1026 881 1027 spin_unlock_irq(&pprt_lock); 882 - 883 - lcd_home(); 884 1028 } 885 1029 886 - /* clears the display and resets X/Y */ 887 - static void lcd_clear_display(void) 888 - { 889 - lcd_write_cmd(LCD_CMD_DISPLAY_CLEAR); 890 - lcd.addr.x = 0; 891 - lcd.addr.y = 0; 892 - /* we must wait a few milliseconds (15) */ 893 - long_sleep(15); 894 - } 895 - 896 - static void lcd_init_display(void) 897 - { 898 - lcd.flags = ((lcd.height > 1) ? LCD_FLAG_N : 0) 899 - | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B; 900 - 901 - long_sleep(20); /* wait 20 ms after power-up for the paranoid */ 902 - 903 - /* 8bits, 1 line, small fonts; let's do it 3 times */ 904 - lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); 905 - long_sleep(10); 906 - lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); 907 - long_sleep(10); 908 - lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS); 909 - long_sleep(10); 910 - 911 - /* set font height and lines number */ 912 - lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS 913 - | ((lcd.flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0) 914 - | ((lcd.flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0) 915 - ); 916 - long_sleep(10); 917 - 918 - /* display off, cursor off, blink off */ 919 - lcd_write_cmd(LCD_CMD_DISPLAY_CTRL); 920 - long_sleep(10); 921 - 922 - lcd_write_cmd(LCD_CMD_DISPLAY_CTRL /* set display mode */ 923 - | ((lcd.flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0) 924 - | ((lcd.flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0) 925 - | ((lcd.flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0) 926 - ); 927 - 928 - lcd_backlight((lcd.flags & LCD_FLAG_L) ? 1 : 0); 929 - 930 - long_sleep(10); 931 - 932 - /* entry mode set : increment, cursor shifting */ 933 - lcd_write_cmd(LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC); 934 - 935 - lcd_clear_display(); 936 - } 937 - 938 - /* 939 - * These are the file operation function for user access to /dev/lcd 940 - * This function can also be called from inside the kernel, by 941 - * setting file and ppos to NULL. 942 - * 943 - */ 944 - 945 - static inline int handle_lcd_special_code(void) 946 - { 947 - /* LCD special codes */ 948 - 949 - int processed = 0; 950 - 951 - char *esc = lcd.esc_seq.buf + 2; 952 - int oldflags = lcd.flags; 953 - 954 - /* check for display mode flags */ 955 - switch (*esc) { 956 - case 'D': /* Display ON */ 957 - lcd.flags |= LCD_FLAG_D; 958 - processed = 1; 959 - break; 960 - case 'd': /* Display OFF */ 961 - lcd.flags &= ~LCD_FLAG_D; 962 - processed = 1; 963 - break; 964 - case 'C': /* Cursor ON */ 965 - lcd.flags |= LCD_FLAG_C; 966 - processed = 1; 967 - break; 968 - case 'c': /* Cursor OFF */ 969 - lcd.flags &= ~LCD_FLAG_C; 970 - processed = 1; 971 - break; 972 - case 'B': /* Blink ON */ 973 - lcd.flags |= LCD_FLAG_B; 974 - processed = 1; 975 - break; 976 - case 'b': /* Blink OFF */ 977 - lcd.flags &= ~LCD_FLAG_B; 978 - processed = 1; 979 - break; 980 - case '+': /* Back light ON */ 981 - lcd.flags |= LCD_FLAG_L; 982 - processed = 1; 983 - break; 984 - case '-': /* Back light OFF */ 985 - lcd.flags &= ~LCD_FLAG_L; 986 - processed = 1; 987 - break; 988 - case '*': 989 - /* flash back light */ 990 - lcd_poke(); 991 - processed = 1; 992 - break; 993 - case 'f': /* Small Font */ 994 - lcd.flags &= ~LCD_FLAG_F; 995 - processed = 1; 996 - break; 997 - case 'F': /* Large Font */ 998 - lcd.flags |= LCD_FLAG_F; 999 - processed = 1; 1000 - break; 1001 - case 'n': /* One Line */ 1002 - lcd.flags &= ~LCD_FLAG_N; 1003 - processed = 1; 1004 - break; 1005 - case 'N': /* Two Lines */ 1006 - lcd.flags |= LCD_FLAG_N; 1007 - break; 1008 - case 'l': /* Shift Cursor Left */ 1009 - if (lcd.addr.x > 0) { 1010 - /* back one char if not at end of line */ 1011 - if (lcd.addr.x < lcd.bwidth) 1012 - lcd_write_cmd(LCD_CMD_SHIFT); 1013 - lcd.addr.x--; 1014 - } 1015 - processed = 1; 1016 - break; 1017 - case 'r': /* shift cursor right */ 1018 - if (lcd.addr.x < lcd.width) { 1019 - /* allow the cursor to pass the end of the line */ 1020 - if (lcd.addr.x < (lcd.bwidth - 1)) 1021 - lcd_write_cmd(LCD_CMD_SHIFT | 1022 - LCD_CMD_SHIFT_RIGHT); 1023 - lcd.addr.x++; 1024 - } 1025 - processed = 1; 1026 - break; 1027 - case 'L': /* shift display left */ 1028 - lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT); 1029 - processed = 1; 1030 - break; 1031 - case 'R': /* shift display right */ 1032 - lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT | 1033 - LCD_CMD_SHIFT_RIGHT); 1034 - processed = 1; 1035 - break; 1036 - case 'k': { /* kill end of line */ 1037 - int x; 1038 - 1039 - for (x = lcd.addr.x; x < lcd.bwidth; x++) 1040 - lcd_write_data(' '); 1041 - 1042 - /* restore cursor position */ 1043 - lcd_gotoxy(); 1044 - processed = 1; 1045 - break; 1046 - } 1047 - case 'I': /* reinitialize display */ 1048 - lcd_init_display(); 1049 - processed = 1; 1050 - break; 1051 - case 'G': { 1052 - /* Generator : LGcxxxxx...xx; must have <c> between '0' 1053 - * and '7', representing the numerical ASCII code of the 1054 - * redefined character, and <xx...xx> a sequence of 16 1055 - * hex digits representing 8 bytes for each character. 1056 - * Most LCDs will only use 5 lower bits of the 7 first 1057 - * bytes. 1058 - */ 1059 - 1060 - unsigned char cgbytes[8]; 1061 - unsigned char cgaddr; 1062 - int cgoffset; 1063 - int shift; 1064 - char value; 1065 - int addr; 1066 - 1067 - if (!strchr(esc, ';')) 1068 - break; 1069 - 1070 - esc++; 1071 - 1072 - cgaddr = *(esc++) - '0'; 1073 - if (cgaddr > 7) { 1074 - processed = 1; 1075 - break; 1076 - } 1077 - 1078 - cgoffset = 0; 1079 - shift = 0; 1080 - value = 0; 1081 - while (*esc && cgoffset < 8) { 1082 - shift ^= 4; 1083 - if (*esc >= '0' && *esc <= '9') { 1084 - value |= (*esc - '0') << shift; 1085 - } else if (*esc >= 'A' && *esc <= 'Z') { 1086 - value |= (*esc - 'A' + 10) << shift; 1087 - } else if (*esc >= 'a' && *esc <= 'z') { 1088 - value |= (*esc - 'a' + 10) << shift; 1089 - } else { 1090 - esc++; 1091 - continue; 1092 - } 1093 - 1094 - if (shift == 0) { 1095 - cgbytes[cgoffset++] = value; 1096 - value = 0; 1097 - } 1098 - 1099 - esc++; 1100 - } 1101 - 1102 - lcd_write_cmd(LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8)); 1103 - for (addr = 0; addr < cgoffset; addr++) 1104 - lcd_write_data(cgbytes[addr]); 1105 - 1106 - /* ensures that we stop writing to CGRAM */ 1107 - lcd_gotoxy(); 1108 - processed = 1; 1109 - break; 1110 - } 1111 - case 'x': /* gotoxy : LxXXX[yYYY]; */ 1112 - case 'y': /* gotoxy : LyYYY[xXXX]; */ 1113 - if (!strchr(esc, ';')) 1114 - break; 1115 - 1116 - while (*esc) { 1117 - if (*esc == 'x') { 1118 - esc++; 1119 - if (kstrtoul(esc, 10, &lcd.addr.x) < 0) 1120 - break; 1121 - } else if (*esc == 'y') { 1122 - esc++; 1123 - if (kstrtoul(esc, 10, &lcd.addr.y) < 0) 1124 - break; 1125 - } else { 1126 - break; 1127 - } 1128 - } 1129 - 1130 - lcd_gotoxy(); 1131 - processed = 1; 1132 - break; 1133 - } 1134 - 1135 - /* TODO: This indent party here got ugly, clean it! */ 1136 - /* Check whether one flag was changed */ 1137 - if (oldflags != lcd.flags) { 1138 - /* check whether one of B,C,D flags were changed */ 1139 - if ((oldflags ^ lcd.flags) & 1140 - (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D)) 1141 - /* set display mode */ 1142 - lcd_write_cmd(LCD_CMD_DISPLAY_CTRL 1143 - | ((lcd.flags & LCD_FLAG_D) 1144 - ? LCD_CMD_DISPLAY_ON : 0) 1145 - | ((lcd.flags & LCD_FLAG_C) 1146 - ? LCD_CMD_CURSOR_ON : 0) 1147 - | ((lcd.flags & LCD_FLAG_B) 1148 - ? LCD_CMD_BLINK_ON : 0)); 1149 - /* check whether one of F,N flags was changed */ 1150 - else if ((oldflags ^ lcd.flags) & (LCD_FLAG_F | LCD_FLAG_N)) 1151 - lcd_write_cmd(LCD_CMD_FUNCTION_SET 1152 - | LCD_CMD_DATA_LEN_8BITS 1153 - | ((lcd.flags & LCD_FLAG_F) 1154 - ? LCD_CMD_FONT_5X10_DOTS 1155 - : 0) 1156 - | ((lcd.flags & LCD_FLAG_N) 1157 - ? LCD_CMD_TWO_LINES 1158 - : 0)); 1159 - /* check whether L flag was changed */ 1160 - else if ((oldflags ^ lcd.flags) & (LCD_FLAG_L)) 1161 - lcd_backlight(!!(lcd.flags & LCD_FLAG_L)); 1162 - } 1163 - 1164 - return processed; 1165 - } 1166 - 1167 - static void lcd_write_char(char c) 1168 - { 1169 - /* first, we'll test if we're in escape mode */ 1170 - if ((c != '\n') && lcd.esc_seq.len >= 0) { 1171 - /* yes, let's add this char to the buffer */ 1172 - lcd.esc_seq.buf[lcd.esc_seq.len++] = c; 1173 - lcd.esc_seq.buf[lcd.esc_seq.len] = 0; 1174 - } else { 1175 - /* aborts any previous escape sequence */ 1176 - lcd.esc_seq.len = -1; 1177 - 1178 - switch (c) { 1179 - case LCD_ESCAPE_CHAR: 1180 - /* start of an escape sequence */ 1181 - lcd.esc_seq.len = 0; 1182 - lcd.esc_seq.buf[lcd.esc_seq.len] = 0; 1183 - break; 1184 - case '\b': 1185 - /* go back one char and clear it */ 1186 - if (lcd.addr.x > 0) { 1187 - /* 1188 - * check if we're not at the 1189 - * end of the line 1190 - */ 1191 - if (lcd.addr.x < lcd.bwidth) 1192 - /* back one char */ 1193 - lcd_write_cmd(LCD_CMD_SHIFT); 1194 - lcd.addr.x--; 1195 - } 1196 - /* replace with a space */ 1197 - lcd_write_data(' '); 1198 - /* back one char again */ 1199 - lcd_write_cmd(LCD_CMD_SHIFT); 1200 - break; 1201 - case '\014': 1202 - /* quickly clear the display */ 1203 - lcd_clear_fast(); 1204 - break; 1205 - case '\n': 1206 - /* 1207 - * flush the remainder of the current line and 1208 - * go to the beginning of the next line 1209 - */ 1210 - for (; lcd.addr.x < lcd.bwidth; lcd.addr.x++) 1211 - lcd_write_data(' '); 1212 - lcd.addr.x = 0; 1213 - lcd.addr.y = (lcd.addr.y + 1) % lcd.height; 1214 - lcd_gotoxy(); 1215 - break; 1216 - case '\r': 1217 - /* go to the beginning of the same line */ 1218 - lcd.addr.x = 0; 1219 - lcd_gotoxy(); 1220 - break; 1221 - case '\t': 1222 - /* print a space instead of the tab */ 1223 - lcd_print(' '); 1224 - break; 1225 - default: 1226 - /* simply print this char */ 1227 - lcd_print(c); 1228 - break; 1229 - } 1230 - } 1231 - 1232 - /* 1233 - * now we'll see if we're in an escape mode and if the current 1234 - * escape sequence can be understood. 1235 - */ 1236 - if (lcd.esc_seq.len >= 2) { 1237 - int processed = 0; 1238 - 1239 - if (!strcmp(lcd.esc_seq.buf, "[2J")) { 1240 - /* clear the display */ 1241 - lcd_clear_fast(); 1242 - processed = 1; 1243 - } else if (!strcmp(lcd.esc_seq.buf, "[H")) { 1244 - /* cursor to home */ 1245 - lcd_home(); 1246 - processed = 1; 1247 - } 1248 - /* codes starting with ^[[L */ 1249 - else if ((lcd.esc_seq.len >= 3) && 1250 - (lcd.esc_seq.buf[0] == '[') && 1251 - (lcd.esc_seq.buf[1] == 'L')) { 1252 - processed = handle_lcd_special_code(); 1253 - } 1254 - 1255 - /* LCD special escape codes */ 1256 - /* 1257 - * flush the escape sequence if it's been processed 1258 - * or if it is getting too long. 1259 - */ 1260 - if (processed || (lcd.esc_seq.len >= LCD_ESCAPE_LEN)) 1261 - lcd.esc_seq.len = -1; 1262 - } /* escape codes */ 1263 - } 1264 - 1265 - static ssize_t lcd_write(struct file *file, 1266 - const char __user *buf, size_t count, loff_t *ppos) 1267 - { 1268 - const char __user *tmp = buf; 1269 - char c; 1270 - 1271 - for (; count-- > 0; (*ppos)++, tmp++) { 1272 - if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) 1273 - /* 1274 - * let's be a little nice with other processes 1275 - * that need some CPU 1276 - */ 1277 - schedule(); 1278 - 1279 - if (get_user(c, tmp)) 1280 - return -EFAULT; 1281 - 1282 - lcd_write_char(c); 1283 - } 1284 - 1285 - return tmp - buf; 1286 - } 1287 - 1288 - static int lcd_open(struct inode *inode, struct file *file) 1289 - { 1290 - if (!atomic_dec_and_test(&lcd_available)) 1291 - return -EBUSY; /* open only once at a time */ 1292 - 1293 - if (file->f_mode & FMODE_READ) /* device is write-only */ 1294 - return -EPERM; 1295 - 1296 - if (lcd.must_clear) { 1297 - lcd_clear_display(); 1298 - lcd.must_clear = false; 1299 - } 1300 - return nonseekable_open(inode, file); 1301 - } 1302 - 1303 - static int lcd_release(struct inode *inode, struct file *file) 1304 - { 1305 - atomic_inc(&lcd_available); 1306 - return 0; 1307 - } 1308 - 1309 - static const struct file_operations lcd_fops = { 1310 - .write = lcd_write, 1311 - .open = lcd_open, 1312 - .release = lcd_release, 1313 - .llseek = no_llseek, 1030 + static struct charlcd_ops charlcd_serial_ops = { 1031 + .write_cmd = lcd_write_cmd_s, 1032 + .write_data = lcd_write_data_s, 1033 + .clear_fast = lcd_clear_fast_s, 1034 + .backlight = lcd_backlight, 1314 1035 }; 1315 1036 1316 - static struct miscdevice lcd_dev = { 1317 - .minor = LCD_MINOR, 1318 - .name = "lcd", 1319 - .fops = &lcd_fops, 1037 + static struct charlcd_ops charlcd_parallel_ops = { 1038 + .write_cmd = lcd_write_cmd_p8, 1039 + .write_data = lcd_write_data_p8, 1040 + .clear_fast = lcd_clear_fast_p8, 1041 + .backlight = lcd_backlight, 1320 1042 }; 1321 1043 1322 - /* public function usable from the kernel for any purpose */ 1323 - static void panel_lcd_print(const char *s) 1324 - { 1325 - const char *tmp = s; 1326 - int count = strlen(s); 1327 - 1328 - if (lcd.enabled && lcd.initialized) { 1329 - for (; count-- > 0; tmp++) { 1330 - if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) 1331 - /* 1332 - * let's be a little nice with other processes 1333 - * that need some CPU 1334 - */ 1335 - schedule(); 1336 - 1337 - lcd_write_char(*tmp); 1338 - } 1339 - } 1340 - } 1044 + static struct charlcd_ops charlcd_tilcd_ops = { 1045 + .write_cmd = lcd_write_cmd_tilcd, 1046 + .write_data = lcd_write_data_tilcd, 1047 + .clear_fast = lcd_clear_fast_tilcd, 1048 + .backlight = lcd_backlight, 1049 + }; 1341 1050 1342 1051 /* initialize the LCD driver */ 1343 1052 static void lcd_init(void) 1344 1053 { 1054 + struct charlcd *charlcd; 1055 + 1056 + charlcd = charlcd_alloc(0); 1057 + if (!charlcd) 1058 + return; 1059 + 1060 + /* 1061 + * Init lcd struct with load-time values to preserve exact 1062 + * current functionality (at least for now). 1063 + */ 1064 + charlcd->height = lcd_height; 1065 + charlcd->width = lcd_width; 1066 + charlcd->bwidth = lcd_bwidth; 1067 + charlcd->hwidth = lcd_hwidth; 1068 + 1345 1069 switch (selected_lcd_type) { 1346 1070 case LCD_TYPE_OLD: 1347 1071 /* parallel mode, 8 bits */ ··· 924 1500 lcd.pins.e = PIN_STROBE; 925 1501 lcd.pins.rs = PIN_AUTOLF; 926 1502 927 - lcd.width = 40; 928 - lcd.bwidth = 40; 929 - lcd.hwidth = 64; 930 - lcd.height = 2; 1503 + charlcd->width = 40; 1504 + charlcd->bwidth = 40; 1505 + charlcd->hwidth = 64; 1506 + charlcd->height = 2; 931 1507 break; 932 1508 case LCD_TYPE_KS0074: 933 1509 /* serial mode, ks0074 */ ··· 937 1513 lcd.pins.cl = PIN_STROBE; 938 1514 lcd.pins.da = PIN_D0; 939 1515 940 - lcd.width = 16; 941 - lcd.bwidth = 40; 942 - lcd.hwidth = 16; 943 - lcd.height = 2; 1516 + charlcd->width = 16; 1517 + charlcd->bwidth = 40; 1518 + charlcd->hwidth = 16; 1519 + charlcd->height = 2; 944 1520 break; 945 1521 case LCD_TYPE_NEXCOM: 946 1522 /* parallel mode, 8 bits, generic */ ··· 950 1526 lcd.pins.rs = PIN_SELECP; 951 1527 lcd.pins.rw = PIN_INITP; 952 1528 953 - lcd.width = 16; 954 - lcd.bwidth = 40; 955 - lcd.hwidth = 64; 956 - lcd.height = 2; 1529 + charlcd->width = 16; 1530 + charlcd->bwidth = 40; 1531 + charlcd->hwidth = 64; 1532 + charlcd->height = 2; 957 1533 break; 958 1534 case LCD_TYPE_CUSTOM: 959 1535 /* customer-defined */ ··· 969 1545 lcd.pins.e = PIN_STROBE; 970 1546 lcd.pins.rs = PIN_SELECP; 971 1547 972 - lcd.width = 16; 973 - lcd.bwidth = 40; 974 - lcd.hwidth = 64; 975 - lcd.height = 2; 1548 + charlcd->width = 16; 1549 + charlcd->bwidth = 40; 1550 + charlcd->hwidth = 64; 1551 + charlcd->height = 2; 976 1552 break; 977 1553 } 978 1554 979 1555 /* Overwrite with module params set on loading */ 980 1556 if (lcd_height != NOT_SET) 981 - lcd.height = lcd_height; 1557 + charlcd->height = lcd_height; 982 1558 if (lcd_width != NOT_SET) 983 - lcd.width = lcd_width; 1559 + charlcd->width = lcd_width; 984 1560 if (lcd_bwidth != NOT_SET) 985 - lcd.bwidth = lcd_bwidth; 1561 + charlcd->bwidth = lcd_bwidth; 986 1562 if (lcd_hwidth != NOT_SET) 987 - lcd.hwidth = lcd_hwidth; 1563 + charlcd->hwidth = lcd_hwidth; 988 1564 if (lcd_charset != NOT_SET) 989 1565 lcd.charset = lcd_charset; 990 1566 if (lcd_proto != NOT_SET) ··· 1003 1579 lcd.pins.bl = lcd_bl_pin; 1004 1580 1005 1581 /* this is used to catch wrong and default values */ 1006 - if (lcd.width <= 0) 1007 - lcd.width = DEFAULT_LCD_WIDTH; 1008 - if (lcd.bwidth <= 0) 1009 - lcd.bwidth = DEFAULT_LCD_BWIDTH; 1010 - if (lcd.hwidth <= 0) 1011 - lcd.hwidth = DEFAULT_LCD_HWIDTH; 1012 - if (lcd.height <= 0) 1013 - lcd.height = DEFAULT_LCD_HEIGHT; 1582 + if (charlcd->width <= 0) 1583 + charlcd->width = DEFAULT_LCD_WIDTH; 1584 + if (charlcd->bwidth <= 0) 1585 + charlcd->bwidth = DEFAULT_LCD_BWIDTH; 1586 + if (charlcd->hwidth <= 0) 1587 + charlcd->hwidth = DEFAULT_LCD_HWIDTH; 1588 + if (charlcd->height <= 0) 1589 + charlcd->height = DEFAULT_LCD_HEIGHT; 1014 1590 1015 1591 if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */ 1016 - lcd_write_cmd = lcd_write_cmd_s; 1017 - lcd_write_data = lcd_write_data_s; 1018 - lcd_clear_fast = lcd_clear_fast_s; 1592 + charlcd->ops = &charlcd_serial_ops; 1019 1593 1020 1594 if (lcd.pins.cl == PIN_NOT_SET) 1021 1595 lcd.pins.cl = DEFAULT_LCD_PIN_SCL; ··· 1021 1599 lcd.pins.da = DEFAULT_LCD_PIN_SDA; 1022 1600 1023 1601 } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */ 1024 - lcd_write_cmd = lcd_write_cmd_p8; 1025 - lcd_write_data = lcd_write_data_p8; 1026 - lcd_clear_fast = lcd_clear_fast_p8; 1602 + charlcd->ops = &charlcd_parallel_ops; 1027 1603 1028 1604 if (lcd.pins.e == PIN_NOT_SET) 1029 1605 lcd.pins.e = DEFAULT_LCD_PIN_E; ··· 1030 1610 if (lcd.pins.rw == PIN_NOT_SET) 1031 1611 lcd.pins.rw = DEFAULT_LCD_PIN_RW; 1032 1612 } else { 1033 - lcd_write_cmd = lcd_write_cmd_tilcd; 1034 - lcd_write_data = lcd_write_data_tilcd; 1035 - lcd_clear_fast = lcd_clear_fast_tilcd; 1613 + charlcd->ops = &charlcd_tilcd_ops; 1036 1614 } 1037 1615 1038 1616 if (lcd.pins.bl == PIN_NOT_SET) ··· 1053 1635 lcd.charset = DEFAULT_LCD_CHARSET; 1054 1636 1055 1637 if (lcd.charset == LCD_CHARSET_KS0074) 1056 - lcd_char_conv = lcd_char_conv_ks0074; 1638 + charlcd->char_conv = lcd_char_conv_ks0074; 1057 1639 else 1058 - lcd_char_conv = NULL; 1059 - 1060 - if (lcd.pins.bl != PIN_NONE) { 1061 - mutex_init(&lcd.bl_tempo_lock); 1062 - INIT_DELAYED_WORK(&lcd.bl_work, lcd_bl_off); 1063 - } 1640 + charlcd->char_conv = NULL; 1064 1641 1065 1642 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E], 1066 1643 lcd_bits[LCD_PORT_C][LCD_BIT_E]); ··· 1070 1657 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA], 1071 1658 lcd_bits[LCD_PORT_C][LCD_BIT_DA]); 1072 1659 1073 - /* 1074 - * before this line, we must NOT send anything to the display. 1075 - * Since lcd_init_display() needs to write data, we have to 1076 - * enable mark the LCD initialized just before. 1077 - */ 1660 + lcd.charlcd = charlcd; 1078 1661 lcd.initialized = true; 1079 - lcd_init_display(); 1080 - 1081 - /* display a short message */ 1082 - #ifdef CONFIG_PANEL_CHANGE_MESSAGE 1083 - #ifdef CONFIG_PANEL_BOOT_MESSAGE 1084 - panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE); 1085 - #endif 1086 - #else 1087 - panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE); 1088 - #endif 1089 - /* clear the display on the next device opening */ 1090 - lcd.must_clear = true; 1091 - lcd_home(); 1092 1662 } 1093 1663 1094 1664 /* ··· 1407 2011 } 1408 2012 1409 2013 if (keypressed && lcd.enabled && lcd.initialized) 1410 - lcd_poke(); 2014 + charlcd_poke(lcd.charlcd); 1411 2015 1412 2016 mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME); 1413 2017 } ··· 1571 2175 /* device initialization */ 1572 2176 /**************************************************/ 1573 2177 1574 - static int panel_notify_sys(struct notifier_block *this, unsigned long code, 1575 - void *unused) 1576 - { 1577 - if (lcd.enabled && lcd.initialized) { 1578 - switch (code) { 1579 - case SYS_DOWN: 1580 - panel_lcd_print 1581 - ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+"); 1582 - break; 1583 - case SYS_HALT: 1584 - panel_lcd_print 1585 - ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+"); 1586 - break; 1587 - case SYS_POWER_OFF: 1588 - panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+"); 1589 - break; 1590 - default: 1591 - break; 1592 - } 1593 - } 1594 - return NOTIFY_DONE; 1595 - } 1596 - 1597 - static struct notifier_block panel_notifier = { 1598 - panel_notify_sys, 1599 - NULL, 1600 - 0 1601 - }; 1602 - 1603 2178 static void panel_attach(struct parport *port) 1604 2179 { 1605 2180 struct pardev_cb panel_cb; ··· 1606 2239 */ 1607 2240 if (lcd.enabled) { 1608 2241 lcd_init(); 1609 - if (misc_register(&lcd_dev)) 2242 + if (!lcd.charlcd || charlcd_register(lcd.charlcd)) 1610 2243 goto err_unreg_device; 1611 2244 } 1612 2245 ··· 1615 2248 if (misc_register(&keypad_dev)) 1616 2249 goto err_lcd_unreg; 1617 2250 } 1618 - register_reboot_notifier(&panel_notifier); 1619 2251 return; 1620 2252 1621 2253 err_lcd_unreg: 1622 2254 if (lcd.enabled) 1623 - misc_deregister(&lcd_dev); 2255 + charlcd_unregister(lcd.charlcd); 1624 2256 err_unreg_device: 2257 + kfree(lcd.charlcd); 2258 + lcd.charlcd = NULL; 1625 2259 parport_unregister_device(pprt); 1626 2260 pprt = NULL; 1627 2261 } ··· 1646 2278 } 1647 2279 1648 2280 if (lcd.enabled) { 1649 - panel_lcd_print("\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-"); 1650 - misc_deregister(&lcd_dev); 1651 - if (lcd.pins.bl != PIN_NONE) { 1652 - cancel_delayed_work_sync(&lcd.bl_work); 1653 - __lcd_backlight(0); 1654 - } 2281 + charlcd_unregister(lcd.charlcd); 1655 2282 lcd.initialized = false; 2283 + kfree(lcd.charlcd); 2284 + lcd.charlcd = NULL; 1656 2285 } 1657 2286 1658 2287 /* TODO: free all input signals */ 1659 2288 parport_release(pprt); 1660 2289 parport_unregister_device(pprt); 1661 2290 pprt = NULL; 1662 - unregister_reboot_notifier(&panel_notifier); 1663 2291 } 1664 2292 1665 2293 static struct parport_driver panel_driver = { ··· 1733 2369 * Init lcd struct with load-time values to preserve exact 1734 2370 * current functionality (at least for now). 1735 2371 */ 1736 - lcd.height = lcd_height; 1737 - lcd.width = lcd_width; 1738 - lcd.bwidth = lcd_bwidth; 1739 - lcd.hwidth = lcd_hwidth; 1740 2372 lcd.charset = lcd_charset; 1741 2373 lcd.proto = lcd_proto; 1742 2374 lcd.pins.e = lcd_e_pin; ··· 1741 2381 lcd.pins.cl = lcd_cl_pin; 1742 2382 lcd.pins.da = lcd_da_pin; 1743 2383 lcd.pins.bl = lcd_bl_pin; 1744 - 1745 - /* Leave it for now, just in case */ 1746 - lcd.esc_seq.len = -1; 1747 2384 } 1748 2385 1749 2386 switch (selected_keypad_type) {
+7
drivers/misc/tsl2550.c
··· 443 443 }; 444 444 MODULE_DEVICE_TABLE(i2c, tsl2550_id); 445 445 446 + static const struct of_device_id tsl2550_of_match[] = { 447 + { .compatible = "taos,tsl2550" }, 448 + { } 449 + }; 450 + MODULE_DEVICE_TABLE(of, tsl2550_of_match); 451 + 446 452 static struct i2c_driver tsl2550_driver = { 447 453 .driver = { 448 454 .name = TSL2550_DRV_NAME, 455 + .of_match_table = tsl2550_of_match, 449 456 .pm = TSL2550_PM_OPS, 450 457 }, 451 458 .probe = tsl2550_probe,
+17 -74
drivers/mtd/ubi/build.c
··· 421 421 } 422 422 423 423 /** 424 - * ubi_sysfs_init - initialize sysfs for an UBI device. 425 - * @ubi: UBI device description object 426 - * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was 427 - * taken 428 - * 429 - * This function returns zero in case of success and a negative error code in 430 - * case of failure. 431 - */ 432 - static int ubi_sysfs_init(struct ubi_device *ubi, int *ref) 433 - { 434 - int err; 435 - 436 - ubi->dev.release = dev_release; 437 - ubi->dev.devt = ubi->cdev.dev; 438 - ubi->dev.class = &ubi_class; 439 - ubi->dev.groups = ubi_dev_groups; 440 - dev_set_name(&ubi->dev, UBI_NAME_STR"%d", ubi->ubi_num); 441 - err = device_register(&ubi->dev); 442 - if (err) 443 - return err; 444 - 445 - *ref = 1; 446 - return 0; 447 - } 448 - 449 - /** 450 - * ubi_sysfs_close - close sysfs for an UBI device. 451 - * @ubi: UBI device description object 452 - */ 453 - static void ubi_sysfs_close(struct ubi_device *ubi) 454 - { 455 - device_unregister(&ubi->dev); 456 - } 457 - 458 - /** 459 424 * kill_volumes - destroy all user volumes. 460 425 * @ubi: UBI device description object 461 426 */ ··· 436 471 /** 437 472 * uif_init - initialize user interfaces for an UBI device. 438 473 * @ubi: UBI device description object 439 - * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was 440 - * taken, otherwise set to %0 441 474 * 442 475 * This function initializes various user interfaces for an UBI device. If the 443 476 * initialization fails at an early stage, this function frees all the 444 - * resources it allocated, returns an error, and @ref is set to %0. However, 445 - * if the initialization fails after the UBI device was registered in the 446 - * driver core subsystem, this function takes a reference to @ubi->dev, because 447 - * otherwise the release function ('dev_release()') would free whole @ubi 448 - * object. The @ref argument is set to %1 in this case. The caller has to put 449 - * this reference. 477 + * resources it allocated, returns an error. 450 478 * 451 479 * This function returns zero in case of success and a negative error code in 452 480 * case of failure. 453 481 */ 454 - static int uif_init(struct ubi_device *ubi, int *ref) 482 + static int uif_init(struct ubi_device *ubi) 455 483 { 456 484 int i, err; 457 485 dev_t dev; 458 486 459 - *ref = 0; 460 487 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 461 488 462 489 /* ··· 465 508 return err; 466 509 } 467 510 511 + ubi->dev.devt = dev; 512 + 468 513 ubi_assert(MINOR(dev) == 0); 469 514 cdev_init(&ubi->cdev, &ubi_cdev_operations); 470 515 dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev)); 471 516 ubi->cdev.owner = THIS_MODULE; 472 517 473 - err = cdev_add(&ubi->cdev, dev, 1); 474 - if (err) { 475 - ubi_err(ubi, "cannot add character device"); 476 - goto out_unreg; 477 - } 478 - 479 - err = ubi_sysfs_init(ubi, ref); 518 + dev_set_name(&ubi->dev, UBI_NAME_STR "%d", ubi->ubi_num); 519 + err = cdev_device_add(&ubi->cdev, &ubi->dev); 480 520 if (err) 481 - goto out_sysfs; 521 + goto out_unreg; 482 522 483 523 for (i = 0; i < ubi->vtbl_slots; i++) 484 524 if (ubi->volumes[i]) { ··· 490 536 491 537 out_volumes: 492 538 kill_volumes(ubi); 493 - out_sysfs: 494 - if (*ref) 495 - get_device(&ubi->dev); 496 - ubi_sysfs_close(ubi); 497 - cdev_del(&ubi->cdev); 539 + cdev_device_del(&ubi->cdev, &ubi->dev); 498 540 out_unreg: 499 541 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 500 542 ubi_err(ubi, "cannot initialize UBI %s, error %d", ··· 509 559 static void uif_close(struct ubi_device *ubi) 510 560 { 511 561 kill_volumes(ubi); 512 - ubi_sysfs_close(ubi); 513 - cdev_del(&ubi->cdev); 562 + cdev_device_del(&ubi->cdev, &ubi->dev); 514 563 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); 515 564 } 516 565 ··· 806 857 int vid_hdr_offset, int max_beb_per1024) 807 858 { 808 859 struct ubi_device *ubi; 809 - int i, err, ref = 0; 860 + int i, err; 810 861 811 862 if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT) 812 863 return -EINVAL; ··· 867 918 ubi = kzalloc(sizeof(struct ubi_device), GFP_KERNEL); 868 919 if (!ubi) 869 920 return -ENOMEM; 921 + 922 + device_initialize(&ubi->dev); 923 + ubi->dev.release = dev_release; 924 + ubi->dev.class = &ubi_class; 925 + ubi->dev.groups = ubi_dev_groups; 870 926 871 927 ubi->mtd = mtd; 872 928 ubi->ubi_num = ubi_num; ··· 949 995 /* Make device "available" before it becomes accessible via sysfs */ 950 996 ubi_devices[ubi_num] = ubi; 951 997 952 - err = uif_init(ubi, &ref); 998 + err = uif_init(ubi); 953 999 if (err) 954 1000 goto out_detach; 955 1001 ··· 999 1045 out_debugfs: 1000 1046 ubi_debugfs_exit_dev(ubi); 1001 1047 out_uif: 1002 - get_device(&ubi->dev); 1003 - ubi_assert(ref); 1004 1048 uif_close(ubi); 1005 1049 out_detach: 1006 1050 ubi_devices[ubi_num] = NULL; ··· 1008 1056 out_free: 1009 1057 vfree(ubi->peb_buf); 1010 1058 vfree(ubi->fm_buf); 1011 - if (ref) 1012 - put_device(&ubi->dev); 1013 - else 1014 - kfree(ubi); 1059 + put_device(&ubi->dev); 1015 1060 return err; 1016 1061 } 1017 1062 ··· 1068 1119 */ 1069 1120 if (ubi->bgt_thread) 1070 1121 kthread_stop(ubi->bgt_thread); 1071 - 1072 - /* 1073 - * Get a reference to the device in order to prevent 'dev_release()' 1074 - * from freeing the @ubi object. 1075 - */ 1076 - get_device(&ubi->dev); 1077 1122 1078 1123 ubi_debugfs_exit_dev(ubi); 1079 1124 uif_close(ubi);
+16 -33
drivers/mtd/ubi/vmt.c
··· 155 155 */ 156 156 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) 157 157 { 158 - int i, err, vol_id = req->vol_id, do_free = 1; 158 + int i, err, vol_id = req->vol_id; 159 159 struct ubi_volume *vol; 160 160 struct ubi_vtbl_record vtbl_rec; 161 161 struct ubi_eba_table *eba_tbl = NULL; 162 - dev_t dev; 163 162 164 163 if (ubi->ro_mode) 165 164 return -EROFS; ··· 166 167 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); 167 168 if (!vol) 168 169 return -ENOMEM; 170 + 171 + device_initialize(&vol->dev); 172 + vol->dev.release = vol_release; 173 + vol->dev.parent = &ubi->dev; 174 + vol->dev.class = &ubi_class; 175 + vol->dev.groups = volume_dev_groups; 169 176 170 177 spin_lock(&ubi->volumes_lock); 171 178 if (vol_id == UBI_VOL_NUM_AUTO) { ··· 273 268 /* Register character device for the volume */ 274 269 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); 275 270 vol->cdev.owner = THIS_MODULE; 276 - dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); 277 - err = cdev_add(&vol->cdev, dev, 1); 278 - if (err) { 279 - ubi_err(ubi, "cannot add character device"); 280 - goto out_mapping; 281 - } 282 271 283 - vol->dev.release = vol_release; 284 - vol->dev.parent = &ubi->dev; 285 - vol->dev.devt = dev; 286 - vol->dev.class = &ubi_class; 287 - vol->dev.groups = volume_dev_groups; 288 - 272 + vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); 289 273 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); 290 - err = device_register(&vol->dev); 274 + err = cdev_device_add(&vol->cdev, &vol->dev); 291 275 if (err) { 292 - ubi_err(ubi, "cannot register device"); 293 - goto out_cdev; 276 + ubi_err(ubi, "cannot add device"); 277 + goto out_mapping; 294 278 } 295 279 296 280 /* Fill volume table record */ ··· 312 318 * We have registered our device, we should not free the volume 313 319 * description object in this function in case of an error - it is 314 320 * freed by the release function. 315 - * 316 - * Get device reference to prevent the release function from being 317 - * called just after sysfs has been closed. 318 321 */ 319 - do_free = 0; 320 - get_device(&vol->dev); 321 - device_unregister(&vol->dev); 322 - out_cdev: 323 - cdev_del(&vol->cdev); 322 + cdev_device_del(&vol->cdev, &vol->dev); 324 323 out_mapping: 325 - if (do_free) 326 - ubi_eba_destroy_table(eba_tbl); 324 + ubi_eba_destroy_table(eba_tbl); 327 325 out_acc: 328 326 spin_lock(&ubi->volumes_lock); 329 327 ubi->rsvd_pebs -= vol->reserved_pebs; 330 328 ubi->avail_pebs += vol->reserved_pebs; 331 329 out_unlock: 332 330 spin_unlock(&ubi->volumes_lock); 333 - if (do_free) 334 - kfree(vol); 335 - else 336 - put_device(&vol->dev); 331 + put_device(&vol->dev); 337 332 ubi_err(ubi, "cannot create volume %d, error %d", vol_id, err); 338 333 return err; 339 334 } ··· 374 391 goto out_err; 375 392 } 376 393 377 - cdev_del(&vol->cdev); 378 - device_unregister(&vol->dev); 394 + cdev_device_del(&vol->cdev, &vol->dev); 395 + put_device(&vol->dev); 379 396 380 397 spin_lock(&ubi->volumes_lock); 381 398 ubi->rsvd_pebs -= reserved_pebs;
+11
drivers/nvmem/Kconfig
··· 13 13 14 14 if NVMEM 15 15 16 + config NVMEM_IMX_IIM 17 + tristate "i.MX IC Identification Module support" 18 + depends on ARCH_MXC || COMPILE_TEST 19 + help 20 + This is a driver for the IC Identification Module (IIM) available on 21 + i.MX SoCs, providing access to 4 Kbits of programmable 22 + eFuses. 23 + 24 + This driver can also be built as a module. If so, the module 25 + will be called nvmem-imx-iim. 26 + 16 27 config NVMEM_IMX_OCOTP 17 28 tristate "i.MX6 On-Chip OTP Controller support" 18 29 depends on SOC_IMX6 || COMPILE_TEST
+2
drivers/nvmem/Makefile
··· 8 8 # Devices 9 9 obj-$(CONFIG_NVMEM_BCM_OCOTP) += nvmem-bcm-ocotp.o 10 10 nvmem-bcm-ocotp-y := bcm-ocotp.o 11 + obj-$(CONFIG_NVMEM_IMX_IIM) += nvmem-imx-iim.o 12 + nvmem-imx-iim-y := imx-iim.o 11 13 obj-$(CONFIG_NVMEM_IMX_OCOTP) += nvmem-imx-ocotp.o 12 14 nvmem-imx-ocotp-y := imx-ocotp.o 13 15 obj-$(CONFIG_NVMEM_LPC18XX_EEPROM) += nvmem_lpc18xx_eeprom.o
+2 -1
drivers/nvmem/core.c
··· 468 468 np = config->dev->of_node; 469 469 nvmem->dev.of_node = np; 470 470 dev_set_name(&nvmem->dev, "%s%d", 471 - config->name ? : "nvmem", config->id); 471 + config->name ? : "nvmem", 472 + config->name ? config->id : nvmem->id); 472 473 473 474 nvmem->read_only = of_property_read_bool(np, "read-only") | 474 475 config->read_only;
+173
drivers/nvmem/imx-iim.c
··· 1 + /* 2 + * i.MX IIM driver 3 + * 4 + * Copyright (c) 2017 Pengutronix, Michael Grzeschik <m.grzeschik@pengutronix.de> 5 + * 6 + * Based on the barebox iim driver, 7 + * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>, 8 + * Orex Computed Radiography 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 12 + * as published by the Free Software Foundation. 13 + * 14 + * http://www.opensource.org/licenses/gpl-license.html 15 + * http://www.gnu.org/copyleft/gpl.html 16 + */ 17 + 18 + #include <linux/device.h> 19 + #include <linux/io.h> 20 + #include <linux/module.h> 21 + #include <linux/nvmem-provider.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/slab.h> 26 + #include <linux/clk.h> 27 + 28 + #define IIM_BANK_BASE(n) (0x800 + 0x400 * (n)) 29 + 30 + struct imx_iim_drvdata { 31 + unsigned int nregs; 32 + }; 33 + 34 + struct iim_priv { 35 + void __iomem *base; 36 + struct clk *clk; 37 + struct nvmem_config nvmem; 38 + }; 39 + 40 + static int imx_iim_read(void *context, unsigned int offset, 41 + void *buf, size_t bytes) 42 + { 43 + struct iim_priv *iim = context; 44 + int i, ret; 45 + u8 *buf8 = buf; 46 + 47 + ret = clk_prepare_enable(iim->clk); 48 + if (ret) 49 + return ret; 50 + 51 + for (i = offset; i < offset + bytes; i++) { 52 + int bank = i >> 5; 53 + int reg = i & 0x1f; 54 + 55 + *buf8++ = readl(iim->base + IIM_BANK_BASE(bank) + reg * 4); 56 + } 57 + 58 + clk_disable_unprepare(iim->clk); 59 + 60 + return 0; 61 + } 62 + 63 + static struct imx_iim_drvdata imx27_drvdata = { 64 + .nregs = 2 * 32, 65 + }; 66 + 67 + static struct imx_iim_drvdata imx25_imx31_imx35_drvdata = { 68 + .nregs = 3 * 32, 69 + }; 70 + 71 + static struct imx_iim_drvdata imx51_drvdata = { 72 + .nregs = 4 * 32, 73 + }; 74 + 75 + static struct imx_iim_drvdata imx53_drvdata = { 76 + .nregs = 4 * 32 + 16, 77 + }; 78 + 79 + static const struct of_device_id imx_iim_dt_ids[] = { 80 + { 81 + .compatible = "fsl,imx25-iim", 82 + .data = &imx25_imx31_imx35_drvdata, 83 + }, { 84 + .compatible = "fsl,imx27-iim", 85 + .data = &imx27_drvdata, 86 + }, { 87 + .compatible = "fsl,imx31-iim", 88 + .data = &imx25_imx31_imx35_drvdata, 89 + }, { 90 + .compatible = "fsl,imx35-iim", 91 + .data = &imx25_imx31_imx35_drvdata, 92 + }, { 93 + .compatible = "fsl,imx51-iim", 94 + .data = &imx51_drvdata, 95 + }, { 96 + .compatible = "fsl,imx53-iim", 97 + .data = &imx53_drvdata, 98 + }, { 99 + /* sentinel */ 100 + }, 101 + }; 102 + MODULE_DEVICE_TABLE(of, imx_iim_dt_ids); 103 + 104 + static int imx_iim_probe(struct platform_device *pdev) 105 + { 106 + const struct of_device_id *of_id; 107 + struct device *dev = &pdev->dev; 108 + struct resource *res; 109 + struct iim_priv *iim; 110 + struct nvmem_device *nvmem; 111 + struct nvmem_config *cfg; 112 + const struct imx_iim_drvdata *drvdata = NULL; 113 + 114 + iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL); 115 + if (!iim) 116 + return -ENOMEM; 117 + 118 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 119 + iim->base = devm_ioremap_resource(dev, res); 120 + if (IS_ERR(iim->base)) 121 + return PTR_ERR(iim->base); 122 + 123 + of_id = of_match_device(imx_iim_dt_ids, dev); 124 + if (!of_id) 125 + return -ENODEV; 126 + 127 + drvdata = of_id->data; 128 + 129 + iim->clk = devm_clk_get(&pdev->dev, NULL); 130 + if (IS_ERR(iim->clk)) 131 + return PTR_ERR(iim->clk); 132 + 133 + cfg = &iim->nvmem; 134 + 135 + cfg->name = "imx-iim", 136 + cfg->read_only = true, 137 + cfg->word_size = 1, 138 + cfg->stride = 1, 139 + cfg->owner = THIS_MODULE, 140 + cfg->reg_read = imx_iim_read, 141 + cfg->dev = dev; 142 + cfg->size = drvdata->nregs; 143 + cfg->priv = iim; 144 + 145 + nvmem = nvmem_register(cfg); 146 + if (IS_ERR(nvmem)) 147 + return PTR_ERR(nvmem); 148 + 149 + platform_set_drvdata(pdev, nvmem); 150 + 151 + return 0; 152 + } 153 + 154 + static int imx_iim_remove(struct platform_device *pdev) 155 + { 156 + struct nvmem_device *nvmem = platform_get_drvdata(pdev); 157 + 158 + return nvmem_unregister(nvmem); 159 + } 160 + 161 + static struct platform_driver imx_iim_driver = { 162 + .probe = imx_iim_probe, 163 + .remove = imx_iim_remove, 164 + .driver = { 165 + .name = "imx-iim", 166 + .of_match_table = imx_iim_dt_ids, 167 + }, 168 + }; 169 + module_platform_driver(imx_iim_driver); 170 + 171 + MODULE_AUTHOR("Michael Grzeschik <m.grzeschik@pengutronix.de>"); 172 + MODULE_DESCRIPTION("i.MX IIM driver"); 173 + MODULE_LICENSE("GPL v2");
+249 -5
drivers/nvmem/imx-ocotp.c
··· 7 7 * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>, 8 8 * Orex Computed Radiography 9 9 * 10 + * Write support based on the fsl_otp driver, 11 + * Copyright (C) 2010-2013 Freescale Semiconductor, Inc 12 + * 10 13 * This program is free software; you can redistribute it and/or modify 11 14 * it under the terms of the GNU General Public License version 2 12 15 * as published by the Free Software Foundation. ··· 27 24 #include <linux/of_device.h> 28 25 #include <linux/platform_device.h> 29 26 #include <linux/slab.h> 27 + #include <linux/delay.h> 28 + 29 + #define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the 30 + * OTP Bank0 Word0 31 + */ 32 + #define IMX_OCOTP_OFFSET_PER_WORD 0x10 /* Offset between the start addr 33 + * of two consecutive OTP words. 34 + */ 35 + 36 + #define IMX_OCOTP_ADDR_CTRL 0x0000 37 + #define IMX_OCOTP_ADDR_CTRL_SET 0x0004 38 + #define IMX_OCOTP_ADDR_CTRL_CLR 0x0008 39 + #define IMX_OCOTP_ADDR_TIMING 0x0010 40 + #define IMX_OCOTP_ADDR_DATA 0x0020 41 + 42 + #define IMX_OCOTP_BM_CTRL_ADDR 0x0000007F 43 + #define IMX_OCOTP_BM_CTRL_BUSY 0x00000100 44 + #define IMX_OCOTP_BM_CTRL_ERROR 0x00000200 45 + #define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400 46 + 47 + #define DEF_RELAX 20 /* > 16.5ns */ 48 + #define IMX_OCOTP_WR_UNLOCK 0x3E770000 49 + #define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA 50 + 51 + static DEFINE_MUTEX(ocotp_mutex); 30 52 31 53 struct ocotp_priv { 32 54 struct device *dev; 33 55 struct clk *clk; 34 56 void __iomem *base; 35 57 unsigned int nregs; 58 + struct nvmem_config *config; 36 59 }; 60 + 61 + static int imx_ocotp_wait_for_busy(void __iomem *base, u32 flags) 62 + { 63 + int count; 64 + u32 c, mask; 65 + 66 + mask = IMX_OCOTP_BM_CTRL_BUSY | IMX_OCOTP_BM_CTRL_ERROR | flags; 67 + 68 + for (count = 10000; count >= 0; count--) { 69 + c = readl(base + IMX_OCOTP_ADDR_CTRL); 70 + if (!(c & mask)) 71 + break; 72 + cpu_relax(); 73 + } 74 + 75 + if (count < 0) { 76 + /* HW_OCOTP_CTRL[ERROR] will be set under the following 77 + * conditions: 78 + * - A write is performed to a shadow register during a shadow 79 + * reload (essentially, while HW_OCOTP_CTRL[RELOAD_SHADOWS] is 80 + * set. In addition, the contents of the shadow register shall 81 + * not be updated. 82 + * - A write is performed to a shadow register which has been 83 + * locked. 84 + * - A read is performed to from a shadow register which has 85 + * been read locked. 86 + * - A program is performed to a fuse word which has been locked 87 + * - A read is performed to from a fuse word which has been read 88 + * locked. 89 + */ 90 + if (c & IMX_OCOTP_BM_CTRL_ERROR) 91 + return -EPERM; 92 + return -ETIMEDOUT; 93 + } 94 + 95 + return 0; 96 + } 97 + 98 + static void imx_ocotp_clr_err_if_set(void __iomem *base) 99 + { 100 + u32 c; 101 + 102 + c = readl(base + IMX_OCOTP_ADDR_CTRL); 103 + if (!(c & IMX_OCOTP_BM_CTRL_ERROR)) 104 + return; 105 + 106 + writel(IMX_OCOTP_BM_CTRL_ERROR, base + IMX_OCOTP_ADDR_CTRL_CLR); 107 + } 37 108 38 109 static int imx_ocotp_read(void *context, unsigned int offset, 39 110 void *val, size_t bytes) ··· 124 47 if (count > (priv->nregs - index)) 125 48 count = priv->nregs - index; 126 49 50 + mutex_lock(&ocotp_mutex); 51 + 127 52 ret = clk_prepare_enable(priv->clk); 128 53 if (ret < 0) { 54 + mutex_unlock(&ocotp_mutex); 129 55 dev_err(priv->dev, "failed to prepare/enable ocotp clk\n"); 130 56 return ret; 131 57 } 132 - for (i = index; i < (index + count); i++) 133 - *buf++ = readl(priv->base + 0x400 + i * 0x10); 134 58 59 + ret = imx_ocotp_wait_for_busy(priv->base, 0); 60 + if (ret < 0) { 61 + dev_err(priv->dev, "timeout during read setup\n"); 62 + goto read_end; 63 + } 64 + 65 + for (i = index; i < (index + count); i++) { 66 + *buf++ = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 + 67 + i * IMX_OCOTP_OFFSET_PER_WORD); 68 + 69 + /* 47.3.1.2 70 + * For "read locked" registers 0xBADABADA will be returned and 71 + * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by 72 + * software before any new write, read or reload access can be 73 + * issued 74 + */ 75 + if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL) 76 + imx_ocotp_clr_err_if_set(priv->base); 77 + } 78 + ret = 0; 79 + 80 + read_end: 135 81 clk_disable_unprepare(priv->clk); 82 + mutex_unlock(&ocotp_mutex); 83 + return ret; 84 + } 136 85 137 - return 0; 86 + static int imx_ocotp_write(void *context, unsigned int offset, void *val, 87 + size_t bytes) 88 + { 89 + struct ocotp_priv *priv = context; 90 + u32 *buf = val; 91 + int ret; 92 + 93 + unsigned long clk_rate = 0; 94 + unsigned long strobe_read, relax, strobe_prog; 95 + u32 timing = 0; 96 + u32 ctrl; 97 + u8 waddr; 98 + 99 + /* allow only writing one complete OTP word at a time */ 100 + if ((bytes != priv->config->word_size) || 101 + (offset % priv->config->word_size)) 102 + return -EINVAL; 103 + 104 + mutex_lock(&ocotp_mutex); 105 + 106 + ret = clk_prepare_enable(priv->clk); 107 + if (ret < 0) { 108 + mutex_unlock(&ocotp_mutex); 109 + dev_err(priv->dev, "failed to prepare/enable ocotp clk\n"); 110 + return ret; 111 + } 112 + 113 + /* 47.3.1.3.1 114 + * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] 115 + * fields with timing values to match the current frequency of the 116 + * ipg_clk. OTP writes will work at maximum bus frequencies as long 117 + * as the HW_OCOTP_TIMING parameters are set correctly. 118 + */ 119 + clk_rate = clk_get_rate(priv->clk); 120 + 121 + relax = clk_rate / (1000000000 / DEF_RELAX) - 1; 122 + strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1; 123 + strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1; 124 + 125 + timing = strobe_prog & 0x00000FFF; 126 + timing |= (relax << 12) & 0x0000F000; 127 + timing |= (strobe_read << 16) & 0x003F0000; 128 + 129 + writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING); 130 + 131 + /* 47.3.1.3.2 132 + * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. 133 + * Overlapped accesses are not supported by the controller. Any pending 134 + * write or reload must be completed before a write access can be 135 + * requested. 136 + */ 137 + ret = imx_ocotp_wait_for_busy(priv->base, 0); 138 + if (ret < 0) { 139 + dev_err(priv->dev, "timeout during timing setup\n"); 140 + goto write_end; 141 + } 142 + 143 + /* 47.3.1.3.3 144 + * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the 145 + * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed 146 + * for each write access. The lock code is documented in the register 147 + * description. Both the unlock code and address can be written in the 148 + * same operation. 149 + */ 150 + /* OTP write/read address specifies one of 128 word address locations */ 151 + waddr = offset / 4; 152 + 153 + ctrl = readl(priv->base + IMX_OCOTP_ADDR_CTRL); 154 + ctrl &= ~IMX_OCOTP_BM_CTRL_ADDR; 155 + ctrl |= waddr & IMX_OCOTP_BM_CTRL_ADDR; 156 + ctrl |= IMX_OCOTP_WR_UNLOCK; 157 + 158 + writel(ctrl, priv->base + IMX_OCOTP_ADDR_CTRL); 159 + 160 + /* 47.3.1.3.4 161 + * Write the data to the HW_OCOTP_DATA register. This will automatically 162 + * set HW_OCOTP_CTRL[BUSY] and clear HW_OCOTP_CTRL[WR_UNLOCK]. To 163 + * protect programming same OTP bit twice, before program OCOTP will 164 + * automatically read fuse value in OTP and use read value to mask 165 + * program data. The controller will use masked program data to program 166 + * a 32-bit word in the OTP per the address in HW_OCOTP_CTRL[ADDR]. Bit 167 + * fields with 1's will result in that OTP bit being programmed. Bit 168 + * fields with 0's will be ignored. At the same time that the write is 169 + * accepted, the controller makes an internal copy of 170 + * HW_OCOTP_CTRL[ADDR] which cannot be updated until the next write 171 + * sequence is initiated. This copy guarantees that erroneous writes to 172 + * HW_OCOTP_CTRL[ADDR] will not affect an active write operation. It 173 + * should also be noted that during the programming HW_OCOTP_DATA will 174 + * shift right (with zero fill). This shifting is required to program 175 + * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be 176 + * modified. 177 + */ 178 + writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA); 179 + 180 + /* 47.4.1.4.5 181 + * Once complete, the controller will clear BUSY. A write request to a 182 + * protected or locked region will result in no OTP access and no 183 + * setting of HW_OCOTP_CTRL[BUSY]. In addition HW_OCOTP_CTRL[ERROR] will 184 + * be set. It must be cleared by software before any new write access 185 + * can be issued. 186 + */ 187 + ret = imx_ocotp_wait_for_busy(priv->base, 0); 188 + if (ret < 0) { 189 + if (ret == -EPERM) { 190 + dev_err(priv->dev, "failed write to locked region"); 191 + imx_ocotp_clr_err_if_set(priv->base); 192 + } else { 193 + dev_err(priv->dev, "timeout during data write\n"); 194 + } 195 + goto write_end; 196 + } 197 + 198 + /* 47.3.1.4 199 + * Write Postamble: Due to internal electrical characteristics of the 200 + * OTP during writes, all OTP operations following a write must be 201 + * separated by 2 us after the clearing of HW_OCOTP_CTRL_BUSY following 202 + * the write. 203 + */ 204 + udelay(2); 205 + 206 + /* reload all shadow registers */ 207 + writel(IMX_OCOTP_BM_CTRL_REL_SHADOWS, 208 + priv->base + IMX_OCOTP_ADDR_CTRL_SET); 209 + ret = imx_ocotp_wait_for_busy(priv->base, 210 + IMX_OCOTP_BM_CTRL_REL_SHADOWS); 211 + if (ret < 0) { 212 + dev_err(priv->dev, "timeout during shadow register reload\n"); 213 + goto write_end; 214 + } 215 + 216 + write_end: 217 + clk_disable_unprepare(priv->clk); 218 + mutex_unlock(&ocotp_mutex); 219 + if (ret < 0) 220 + return ret; 221 + return bytes; 138 222 } 139 223 140 224 static struct nvmem_config imx_ocotp_nvmem_config = { 141 225 .name = "imx-ocotp", 142 - .read_only = true, 226 + .read_only = false, 143 227 .word_size = 4, 144 228 .stride = 4, 145 229 .owner = THIS_MODULE, 146 230 .reg_read = imx_ocotp_read, 231 + .reg_write = imx_ocotp_write, 147 232 }; 148 233 149 234 static const struct of_device_id imx_ocotp_dt_ids[] = { ··· 313 74 { .compatible = "fsl,imx6sl-ocotp", (void *)64 }, 314 75 { .compatible = "fsl,imx6sx-ocotp", (void *)128 }, 315 76 { .compatible = "fsl,imx6ul-ocotp", (void *)128 }, 77 + { .compatible = "fsl,imx7d-ocotp", (void *)64 }, 316 78 { }, 317 79 }; 318 80 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); ··· 330 90 if (!priv) 331 91 return -ENOMEM; 332 92 93 + priv->dev = dev; 94 + 333 95 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 334 96 priv->base = devm_ioremap_resource(dev, res); 335 97 if (IS_ERR(priv->base)) 336 98 return PTR_ERR(priv->base); 337 99 338 - priv->clk = devm_clk_get(&pdev->dev, NULL); 100 + priv->clk = devm_clk_get(dev, NULL); 339 101 if (IS_ERR(priv->clk)) 340 102 return PTR_ERR(priv->clk); 341 103 ··· 346 104 imx_ocotp_nvmem_config.size = 4 * priv->nregs; 347 105 imx_ocotp_nvmem_config.dev = dev; 348 106 imx_ocotp_nvmem_config.priv = priv; 107 + priv->config = &imx_ocotp_nvmem_config; 349 108 nvmem = nvmem_register(&imx_ocotp_nvmem_config); 109 + 350 110 if (IS_ERR(nvmem)) 351 111 return PTR_ERR(nvmem); 352 112
+85 -4
drivers/nvmem/sunxi_sid.c
··· 17 17 18 18 #include <linux/device.h> 19 19 #include <linux/io.h> 20 + #include <linux/iopoll.h> 20 21 #include <linux/module.h> 21 22 #include <linux/nvmem-provider.h> 22 23 #include <linux/of.h> 24 + #include <linux/of_device.h> 23 25 #include <linux/platform_device.h> 24 26 #include <linux/slab.h> 25 27 #include <linux/random.h> 28 + 29 + /* Registers and special values for doing register-based SID readout on H3 */ 30 + #define SUN8I_SID_PRCTL 0x40 31 + #define SUN8I_SID_RDKEY 0x60 32 + 33 + #define SUN8I_SID_OFFSET_MASK 0x1FF 34 + #define SUN8I_SID_OFFSET_SHIFT 16 35 + #define SUN8I_SID_OP_LOCK (0xAC << 8) 36 + #define SUN8I_SID_READ BIT(1) 26 37 27 38 static struct nvmem_config econfig = { 28 39 .name = "sunxi-sid", ··· 43 32 .owner = THIS_MODULE, 44 33 }; 45 34 35 + struct sunxi_sid_cfg { 36 + u32 value_offset; 37 + u32 size; 38 + bool need_register_readout; 39 + }; 40 + 46 41 struct sunxi_sid { 47 42 void __iomem *base; 43 + u32 value_offset; 48 44 }; 49 45 50 46 /* We read the entire key, due to a 32 bit read alignment requirement. Since we ··· 76 58 struct sunxi_sid *sid = context; 77 59 u8 *buf = val; 78 60 61 + /* Offset the read operation to the real position of SID */ 62 + offset += sid->value_offset; 63 + 79 64 while (bytes--) 80 65 *buf++ = sunxi_sid_read_byte(sid, offset++); 81 66 67 + return 0; 68 + } 69 + 70 + static int sun8i_sid_register_readout(const struct sunxi_sid *sid, 71 + const unsigned int word) 72 + { 73 + u32 reg_val; 74 + int ret; 75 + 76 + /* Set word, lock access, and set read command */ 77 + reg_val = (word & SUN8I_SID_OFFSET_MASK) 78 + << SUN8I_SID_OFFSET_SHIFT; 79 + reg_val |= SUN8I_SID_OP_LOCK | SUN8I_SID_READ; 80 + writel(reg_val, sid->base + SUN8I_SID_PRCTL); 81 + 82 + ret = readl_poll_timeout(sid->base + SUN8I_SID_PRCTL, reg_val, 83 + !(reg_val & SUN8I_SID_READ), 100, 250000); 84 + if (ret) 85 + return ret; 86 + 87 + writel(0, sid->base + SUN8I_SID_PRCTL); 82 88 return 0; 83 89 } 84 90 ··· 114 72 struct sunxi_sid *sid; 115 73 int ret, i, size; 116 74 char *randomness; 75 + const struct sunxi_sid_cfg *cfg; 117 76 118 77 sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); 119 78 if (!sid) 120 79 return -ENOMEM; 80 + 81 + cfg = of_device_get_match_data(dev); 82 + if (!cfg) 83 + return -EINVAL; 84 + sid->value_offset = cfg->value_offset; 121 85 122 86 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 123 87 sid->base = devm_ioremap_resource(dev, res); 124 88 if (IS_ERR(sid->base)) 125 89 return PTR_ERR(sid->base); 126 90 127 - size = resource_size(res) - 1; 128 - econfig.size = resource_size(res); 91 + size = cfg->size; 92 + 93 + if (cfg->need_register_readout) { 94 + /* 95 + * H3's SID controller have a bug that the value at 0x200 96 + * offset is not the correct value when the hardware is reseted. 97 + * However, after doing a register-based read operation, the 98 + * value become right. 99 + * Do a full read operation here, but ignore its value 100 + * (as it's more fast to read by direct MMIO value than 101 + * with registers) 102 + */ 103 + for (i = 0; i < (size >> 2); i++) { 104 + ret = sun8i_sid_register_readout(sid, i); 105 + if (ret) 106 + return ret; 107 + } 108 + } 109 + 110 + econfig.size = size; 129 111 econfig.dev = dev; 130 112 econfig.reg_read = sunxi_sid_read; 131 113 econfig.priv = sid; ··· 185 119 return nvmem_unregister(nvmem); 186 120 } 187 121 122 + static const struct sunxi_sid_cfg sun4i_a10_cfg = { 123 + .size = 0x10, 124 + }; 125 + 126 + static const struct sunxi_sid_cfg sun7i_a20_cfg = { 127 + .size = 0x200, 128 + }; 129 + 130 + static const struct sunxi_sid_cfg sun8i_h3_cfg = { 131 + .value_offset = 0x200, 132 + .size = 0x100, 133 + .need_register_readout = true, 134 + }; 135 + 188 136 static const struct of_device_id sunxi_sid_of_match[] = { 189 - { .compatible = "allwinner,sun4i-a10-sid" }, 190 - { .compatible = "allwinner,sun7i-a20-sid" }, 137 + { .compatible = "allwinner,sun4i-a10-sid", .data = &sun4i_a10_cfg }, 138 + { .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg }, 139 + { .compatible = "allwinner,sun8i-h3-sid", .data = &sun8i_h3_cfg }, 191 140 {/* sentinel */}, 192 141 }; 193 142 MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
+7 -24
drivers/platform/chrome/cros_ec_dev.c
··· 391 391 int retval = -ENOMEM; 392 392 struct device *dev = &pdev->dev; 393 393 struct cros_ec_platform *ec_platform = dev_get_platdata(dev); 394 - dev_t devno = MKDEV(ec_major, pdev->id); 395 394 struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL); 396 395 397 396 if (!ec) ··· 406 407 cdev_init(&ec->cdev, &fops); 407 408 408 409 /* 409 - * Add the character device 410 - * Link cdev to the class device to be sure device is not used 411 - * before unbinding it. 412 - */ 413 - ec->cdev.kobj.parent = &ec->class_dev.kobj; 414 - retval = cdev_add(&ec->cdev, devno, 1); 415 - if (retval) { 416 - dev_err(dev, ": failed to add character device\n"); 417 - goto cdev_add_failed; 418 - } 419 - 420 - /* 421 410 * Add the class device 422 411 * Link to the character device for creating the /dev entry 423 412 * in devtmpfs. 424 413 */ 425 - ec->class_dev.devt = ec->cdev.dev; 414 + ec->class_dev.devt = MKDEV(ec_major, pdev->id); 426 415 ec->class_dev.class = &cros_class; 427 416 ec->class_dev.parent = dev; 428 417 ec->class_dev.release = __remove; ··· 418 431 retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name); 419 432 if (retval) { 420 433 dev_err(dev, "dev_set_name failed => %d\n", retval); 421 - goto set_named_failed; 434 + goto failed; 422 435 } 423 436 424 - retval = device_add(&ec->class_dev); 437 + retval = cdev_device_add(&ec->cdev, &ec->class_dev); 425 438 if (retval) { 426 - dev_err(dev, "device_register failed => %d\n", retval); 427 - goto dev_reg_failed; 439 + dev_err(dev, "cdev_device_add failed => %d\n", retval); 440 + goto failed; 428 441 } 429 442 430 443 /* check whether this EC is a sensor hub. */ ··· 433 446 434 447 return 0; 435 448 436 - dev_reg_failed: 437 - set_named_failed: 438 - dev_set_drvdata(dev, NULL); 439 - cdev_del(&ec->cdev); 440 - cdev_add_failed: 441 - kfree(ec); 449 + failed: 450 + put_device(&ec->class_dev); 442 451 return retval; 443 452 } 444 453
+670 -358
drivers/platform/goldfish/goldfish_pipe.c
··· 1 1 /* 2 - * Copyright (C) 2011 Google, Inc. 3 2 * Copyright (C) 2012 Intel, Inc. 4 3 * Copyright (C) 2013 Intel, Inc. 5 4 * Copyright (C) 2014 Linaro Limited 5 + * Copyright (C) 2011-2016 Google, Inc. 6 6 * 7 7 * This software is licensed under the terms of the GNU General Public 8 8 * License version 2, as published by the Free Software Foundation, and ··· 46 46 * exchange is properly mapped during a transfer. 47 47 */ 48 48 49 + 49 50 #include <linux/module.h> 50 51 #include <linux/interrupt.h> 51 52 #include <linux/kernel.h> ··· 64 63 #include <linux/acpi.h> 65 64 66 65 /* 66 + * Update this when something changes in the driver's behavior so the host 67 + * can benefit from knowing it 68 + */ 69 + enum { 70 + PIPE_DRIVER_VERSION = 2, 71 + PIPE_CURRENT_DEVICE_VERSION = 2 72 + }; 73 + 74 + /* 67 75 * IMPORTANT: The following constants must match the ones used and defined 68 76 * in external/qemu/hw/goldfish_pipe.c in the Android source tree. 69 77 */ 70 78 71 - /* pipe device registers */ 72 - #define PIPE_REG_COMMAND 0x00 /* write: value = command */ 73 - #define PIPE_REG_STATUS 0x04 /* read */ 74 - #define PIPE_REG_CHANNEL 0x08 /* read/write: channel id */ 75 - #define PIPE_REG_CHANNEL_HIGH 0x30 /* read/write: channel id */ 76 - #define PIPE_REG_SIZE 0x0c /* read/write: buffer size */ 77 - #define PIPE_REG_ADDRESS 0x10 /* write: physical address */ 78 - #define PIPE_REG_ADDRESS_HIGH 0x34 /* write: physical address */ 79 - #define PIPE_REG_WAKES 0x14 /* read: wake flags */ 80 - #define PIPE_REG_PARAMS_ADDR_LOW 0x18 /* read/write: batch data address */ 81 - #define PIPE_REG_PARAMS_ADDR_HIGH 0x1c /* read/write: batch data address */ 82 - #define PIPE_REG_ACCESS_PARAMS 0x20 /* write: batch access */ 83 - #define PIPE_REG_VERSION 0x24 /* read: device version */ 84 - 85 - /* list of commands for PIPE_REG_COMMAND */ 86 - #define CMD_OPEN 1 /* open new channel */ 87 - #define CMD_CLOSE 2 /* close channel (from guest) */ 88 - #define CMD_POLL 3 /* poll read/write status */ 89 - 90 79 /* List of bitflags returned in status of CMD_POLL command */ 91 - #define PIPE_POLL_IN (1 << 0) 92 - #define PIPE_POLL_OUT (1 << 1) 93 - #define PIPE_POLL_HUP (1 << 2) 94 - 95 - /* The following commands are related to write operations */ 96 - #define CMD_WRITE_BUFFER 4 /* send a user buffer to the emulator */ 97 - #define CMD_WAKE_ON_WRITE 5 /* tell the emulator to wake us when writing 98 - is possible */ 99 - #define CMD_READ_BUFFER 6 /* receive a user buffer from the emulator */ 100 - #define CMD_WAKE_ON_READ 7 /* tell the emulator to wake us when reading 101 - * is possible */ 80 + enum PipePollFlags { 81 + PIPE_POLL_IN = 1 << 0, 82 + PIPE_POLL_OUT = 1 << 1, 83 + PIPE_POLL_HUP = 1 << 2 84 + }; 102 85 103 86 /* Possible status values used to signal errors - see goldfish_pipe_error_convert */ 104 - #define PIPE_ERROR_INVAL -1 105 - #define PIPE_ERROR_AGAIN -2 106 - #define PIPE_ERROR_NOMEM -3 107 - #define PIPE_ERROR_IO -4 87 + enum PipeErrors { 88 + PIPE_ERROR_INVAL = -1, 89 + PIPE_ERROR_AGAIN = -2, 90 + PIPE_ERROR_NOMEM = -3, 91 + PIPE_ERROR_IO = -4 92 + }; 108 93 109 94 /* Bit-flags used to signal events from the emulator */ 110 - #define PIPE_WAKE_CLOSED (1 << 0) /* emulator closed pipe */ 111 - #define PIPE_WAKE_READ (1 << 1) /* pipe can now be read from */ 112 - #define PIPE_WAKE_WRITE (1 << 2) /* pipe can now be written to */ 95 + enum PipeWakeFlags { 96 + PIPE_WAKE_CLOSED = 1 << 0, /* emulator closed pipe */ 97 + PIPE_WAKE_READ = 1 << 1, /* pipe can now be read from */ 98 + PIPE_WAKE_WRITE = 1 << 2 /* pipe can now be written to */ 99 + }; 113 100 114 - struct access_params { 115 - unsigned long channel; 116 - u32 size; 117 - unsigned long address; 118 - u32 cmd; 119 - u32 result; 120 - /* reserved for future extension */ 101 + /* Bit flags for the 'flags' field */ 102 + enum PipeFlagsBits { 103 + BIT_CLOSED_ON_HOST = 0, /* pipe closed by host */ 104 + BIT_WAKE_ON_WRITE = 1, /* want to be woken on writes */ 105 + BIT_WAKE_ON_READ = 2, /* want to be woken on reads */ 106 + }; 107 + 108 + enum PipeRegs { 109 + PIPE_REG_CMD = 0, 110 + 111 + PIPE_REG_SIGNAL_BUFFER_HIGH = 4, 112 + PIPE_REG_SIGNAL_BUFFER = 8, 113 + PIPE_REG_SIGNAL_BUFFER_COUNT = 12, 114 + 115 + PIPE_REG_OPEN_BUFFER_HIGH = 20, 116 + PIPE_REG_OPEN_BUFFER = 24, 117 + 118 + PIPE_REG_VERSION = 36, 119 + 120 + PIPE_REG_GET_SIGNALLED = 48, 121 + }; 122 + 123 + enum PipeCmdCode { 124 + PIPE_CMD_OPEN = 1, /* to be used by the pipe device itself */ 125 + PIPE_CMD_CLOSE, 126 + PIPE_CMD_POLL, 127 + PIPE_CMD_WRITE, 128 + PIPE_CMD_WAKE_ON_WRITE, 129 + PIPE_CMD_READ, 130 + PIPE_CMD_WAKE_ON_READ, 131 + 132 + /* 133 + * TODO(zyy): implement a deferred read/write execution to allow 134 + * parallel processing of pipe operations on the host. 135 + */ 136 + PIPE_CMD_WAKE_ON_DONE_IO, 137 + }; 138 + 139 + enum { 140 + MAX_BUFFERS_PER_COMMAND = 336, 141 + MAX_SIGNALLED_PIPES = 64, 142 + INITIAL_PIPES_CAPACITY = 64 143 + }; 144 + 145 + struct goldfish_pipe_dev; 146 + struct goldfish_pipe; 147 + struct goldfish_pipe_command; 148 + 149 + /* A per-pipe command structure, shared with the host */ 150 + struct goldfish_pipe_command { 151 + s32 cmd; /* PipeCmdCode, guest -> host */ 152 + s32 id; /* pipe id, guest -> host */ 153 + s32 status; /* command execution status, host -> guest */ 154 + s32 reserved; /* to pad to 64-bit boundary */ 155 + union { 156 + /* Parameters for PIPE_CMD_{READ,WRITE} */ 157 + struct { 158 + /* number of buffers, guest -> host */ 159 + u32 buffers_count; 160 + /* number of consumed bytes, host -> guest */ 161 + s32 consumed_size; 162 + /* buffer pointers, guest -> host */ 163 + u64 ptrs[MAX_BUFFERS_PER_COMMAND]; 164 + /* buffer sizes, guest -> host */ 165 + u32 sizes[MAX_BUFFERS_PER_COMMAND]; 166 + } rw_params; 167 + }; 168 + }; 169 + 170 + /* A single signalled pipe information */ 171 + struct signalled_pipe_buffer { 172 + u32 id; 121 173 u32 flags; 174 + }; 175 + 176 + /* Parameters for the PIPE_CMD_OPEN command */ 177 + struct open_command_param { 178 + u64 command_buffer_ptr; 179 + u32 rw_params_max_count; 180 + }; 181 + 182 + /* Device-level set of buffers shared with the host */ 183 + struct goldfish_pipe_dev_buffers { 184 + struct open_command_param open_command_params; 185 + struct signalled_pipe_buffer signalled_pipe_buffers[ 186 + MAX_SIGNALLED_PIPES]; 187 + }; 188 + 189 + /* This data type models a given pipe instance */ 190 + struct goldfish_pipe { 191 + /* pipe ID - index into goldfish_pipe_dev::pipes array */ 192 + u32 id; 193 + /* The wake flags pipe is waiting for 194 + * Note: not protected with any lock, uses atomic operations 195 + * and barriers to make it thread-safe. 196 + */ 197 + unsigned long flags; 198 + /* wake flags host have signalled, 199 + * - protected by goldfish_pipe_dev::lock 200 + */ 201 + unsigned long signalled_flags; 202 + 203 + /* A pointer to command buffer */ 204 + struct goldfish_pipe_command *command_buffer; 205 + 206 + /* doubly linked list of signalled pipes, protected by 207 + * goldfish_pipe_dev::lock 208 + */ 209 + struct goldfish_pipe *prev_signalled; 210 + struct goldfish_pipe *next_signalled; 211 + 212 + /* 213 + * A pipe's own lock. Protects the following: 214 + * - *command_buffer - makes sure a command can safely write its 215 + * parameters to the host and read the results back. 216 + */ 217 + struct mutex lock; 218 + 219 + /* A wake queue for sleeping until host signals an event */ 220 + wait_queue_head_t wake_queue; 221 + /* Pointer to the parent goldfish_pipe_dev instance */ 222 + struct goldfish_pipe_dev *dev; 122 223 }; 123 224 124 225 /* The global driver data. Holds a reference to the i/o page used to ··· 228 125 * waiting to be awoken. 229 126 */ 230 127 struct goldfish_pipe_dev { 128 + /* 129 + * Global device spinlock. Protects the following members: 130 + * - pipes, pipes_capacity 131 + * - [*pipes, *pipes + pipes_capacity) - array data 132 + * - first_signalled_pipe, 133 + * goldfish_pipe::prev_signalled, 134 + * goldfish_pipe::next_signalled, 135 + * goldfish_pipe::signalled_flags - all singnalled-related fields, 136 + * in all allocated pipes 137 + * - open_command_params - PIPE_CMD_OPEN-related buffers 138 + * 139 + * It looks like a lot of different fields, but the trick is that 140 + * the only operation that happens often is the signalled pipes array 141 + * manipulation. That's why it's OK for now to keep the rest of the 142 + * fields under the same lock. If we notice too much contention because 143 + * of PIPE_CMD_OPEN, then we should add a separate lock there. 144 + */ 231 145 spinlock_t lock; 232 - unsigned char __iomem *base; 233 - struct access_params *aps; 146 + 147 + /* 148 + * Array of the pipes of |pipes_capacity| elements, 149 + * indexed by goldfish_pipe::id 150 + */ 151 + struct goldfish_pipe **pipes; 152 + u32 pipes_capacity; 153 + 154 + /* Pointers to the buffers host uses for interaction with this driver */ 155 + struct goldfish_pipe_dev_buffers *buffers; 156 + 157 + /* Head of a doubly linked list of signalled pipes */ 158 + struct goldfish_pipe *first_signalled_pipe; 159 + 160 + /* Some device-specific data */ 234 161 int irq; 235 - u32 version; 162 + int version; 163 + unsigned char __iomem *base; 236 164 }; 237 165 238 - static struct goldfish_pipe_dev pipe_dev[1]; 166 + struct goldfish_pipe_dev pipe_dev[1] = {}; 239 167 240 - /* This data type models a given pipe instance */ 241 - struct goldfish_pipe { 242 - struct goldfish_pipe_dev *dev; 243 - struct mutex lock; 244 - unsigned long flags; 245 - wait_queue_head_t wake_queue; 246 - }; 247 - 248 - 249 - /* Bit flags for the 'flags' field */ 250 - enum { 251 - BIT_CLOSED_ON_HOST = 0, /* pipe closed by host */ 252 - BIT_WAKE_ON_WRITE = 1, /* want to be woken on writes */ 253 - BIT_WAKE_ON_READ = 2, /* want to be woken on reads */ 254 - }; 255 - 256 - 257 - static u32 goldfish_cmd_status(struct goldfish_pipe *pipe, u32 cmd) 168 + static int goldfish_cmd_locked(struct goldfish_pipe *pipe, enum PipeCmdCode cmd) 258 169 { 259 - unsigned long flags; 260 - u32 status; 261 - struct goldfish_pipe_dev *dev = pipe->dev; 170 + pipe->command_buffer->cmd = cmd; 171 + /* failure by default */ 172 + pipe->command_buffer->status = PIPE_ERROR_INVAL; 173 + writel(pipe->id, pipe->dev->base + PIPE_REG_CMD); 174 + return pipe->command_buffer->status; 175 + } 262 176 263 - spin_lock_irqsave(&dev->lock, flags); 264 - gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 265 - dev->base + PIPE_REG_CHANNEL_HIGH); 266 - writel(cmd, dev->base + PIPE_REG_COMMAND); 267 - status = readl(dev->base + PIPE_REG_STATUS); 268 - spin_unlock_irqrestore(&dev->lock, flags); 177 + static int goldfish_cmd(struct goldfish_pipe *pipe, enum PipeCmdCode cmd) 178 + { 179 + int status; 180 + 181 + if (mutex_lock_interruptible(&pipe->lock)) 182 + return PIPE_ERROR_IO; 183 + status = goldfish_cmd_locked(pipe, cmd); 184 + mutex_unlock(&pipe->lock); 269 185 return status; 270 186 } 271 187 272 - static void goldfish_cmd(struct goldfish_pipe *pipe, u32 cmd) 273 - { 274 - unsigned long flags; 275 - struct goldfish_pipe_dev *dev = pipe->dev; 276 - 277 - spin_lock_irqsave(&dev->lock, flags); 278 - gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 279 - dev->base + PIPE_REG_CHANNEL_HIGH); 280 - writel(cmd, dev->base + PIPE_REG_COMMAND); 281 - spin_unlock_irqrestore(&dev->lock, flags); 282 - } 283 - 284 - /* This function converts an error code returned by the emulator through 188 + /* 189 + * This function converts an error code returned by the emulator through 285 190 * the PIPE_REG_STATUS i/o register into a valid negative errno value. 286 191 */ 287 192 static int goldfish_pipe_error_convert(int status) ··· 306 195 } 307 196 } 308 197 309 - /* 310 - * Notice: QEMU will return 0 for un-known register access, indicating 311 - * param_acess is supported or not 312 - */ 313 - static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev, 314 - struct access_params *aps) 198 + static int pin_user_pages(unsigned long first_page, unsigned long last_page, 199 + unsigned int last_page_size, int is_write, 200 + struct page *pages[MAX_BUFFERS_PER_COMMAND], 201 + unsigned int *iter_last_page_size) 315 202 { 316 - u32 aph, apl; 317 - u64 paddr; 318 - aph = readl(dev->base + PIPE_REG_PARAMS_ADDR_HIGH); 319 - apl = readl(dev->base + PIPE_REG_PARAMS_ADDR_LOW); 203 + int ret; 204 + int requested_pages = ((last_page - first_page) >> PAGE_SHIFT) + 1; 320 205 321 - paddr = ((u64)aph << 32) | apl; 322 - if (paddr != (__pa(aps))) 323 - return 0; 324 - return 1; 325 - } 206 + if (requested_pages > MAX_BUFFERS_PER_COMMAND) { 207 + requested_pages = MAX_BUFFERS_PER_COMMAND; 208 + *iter_last_page_size = PAGE_SIZE; 209 + } else { 210 + *iter_last_page_size = last_page_size; 211 + } 326 212 327 - /* 0 on success */ 328 - static int setup_access_params_addr(struct platform_device *pdev, 329 - struct goldfish_pipe_dev *dev) 330 - { 331 - dma_addr_t dma_handle; 332 - struct access_params *aps; 333 - 334 - aps = dmam_alloc_coherent(&pdev->dev, sizeof(struct access_params), 335 - &dma_handle, GFP_KERNEL); 336 - if (!aps) 337 - return -ENOMEM; 338 - 339 - writel(upper_32_bits(dma_handle), dev->base + PIPE_REG_PARAMS_ADDR_HIGH); 340 - writel(lower_32_bits(dma_handle), dev->base + PIPE_REG_PARAMS_ADDR_LOW); 341 - 342 - if (valid_batchbuffer_addr(dev, aps)) { 343 - dev->aps = aps; 344 - return 0; 345 - } else 346 - return -1; 347 - } 348 - 349 - /* A value that will not be set by qemu emulator */ 350 - #define INITIAL_BATCH_RESULT (0xdeadbeaf) 351 - static int access_with_param(struct goldfish_pipe_dev *dev, const int cmd, 352 - unsigned long address, unsigned long avail, 353 - struct goldfish_pipe *pipe, int *status) 354 - { 355 - struct access_params *aps = dev->aps; 356 - 357 - if (aps == NULL) 358 - return -1; 359 - 360 - aps->result = INITIAL_BATCH_RESULT; 361 - aps->channel = (unsigned long)pipe; 362 - aps->size = avail; 363 - aps->address = address; 364 - aps->cmd = cmd; 365 - writel(cmd, dev->base + PIPE_REG_ACCESS_PARAMS); 366 - /* 367 - * If the aps->result has not changed, that means 368 - * that the batch command failed 369 - */ 370 - if (aps->result == INITIAL_BATCH_RESULT) 371 - return -1; 372 - *status = aps->result; 373 - return 0; 374 - } 375 - 376 - static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer, 377 - size_t bufflen, int is_write) 378 - { 379 - unsigned long irq_flags; 380 - struct goldfish_pipe *pipe = filp->private_data; 381 - struct goldfish_pipe_dev *dev = pipe->dev; 382 - unsigned long address, address_end; 383 - int count = 0, ret = -EINVAL; 384 - 385 - /* If the emulator already closed the pipe, no need to go further */ 386 - if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) 387 - return -EIO; 388 - 389 - /* Null reads or writes succeeds */ 390 - if (unlikely(bufflen == 0)) 391 - return 0; 392 - 393 - /* Check the buffer range for access */ 394 - if (!access_ok(is_write ? VERIFY_WRITE : VERIFY_READ, 395 - buffer, bufflen)) 213 + ret = get_user_pages_fast( 214 + first_page, requested_pages, !is_write, pages); 215 + if (ret <= 0) 396 216 return -EFAULT; 217 + if (ret < requested_pages) 218 + *iter_last_page_size = PAGE_SIZE; 219 + return ret; 397 220 398 - /* Serialize access to the pipe */ 221 + } 222 + 223 + static void release_user_pages(struct page **pages, int pages_count, 224 + int is_write, s32 consumed_size) 225 + { 226 + int i; 227 + 228 + for (i = 0; i < pages_count; i++) { 229 + if (!is_write && consumed_size > 0) 230 + set_page_dirty(pages[i]); 231 + put_page(pages[i]); 232 + } 233 + } 234 + 235 + /* Populate the call parameters, merging adjacent pages together */ 236 + static void populate_rw_params( 237 + struct page **pages, int pages_count, 238 + unsigned long address, unsigned long address_end, 239 + unsigned long first_page, unsigned long last_page, 240 + unsigned int iter_last_page_size, int is_write, 241 + struct goldfish_pipe_command *command) 242 + { 243 + /* 244 + * Process the first page separately - it's the only page that 245 + * needs special handling for its start address. 246 + */ 247 + unsigned long xaddr = page_to_phys(pages[0]); 248 + unsigned long xaddr_prev = xaddr; 249 + int buffer_idx = 0; 250 + int i = 1; 251 + int size_on_page = first_page == last_page 252 + ? (int)(address_end - address) 253 + : (PAGE_SIZE - (address & ~PAGE_MASK)); 254 + command->rw_params.ptrs[0] = (u64)(xaddr | (address & ~PAGE_MASK)); 255 + command->rw_params.sizes[0] = size_on_page; 256 + for (; i < pages_count; ++i) { 257 + xaddr = page_to_phys(pages[i]); 258 + size_on_page = (i == pages_count - 1) ? 259 + iter_last_page_size : PAGE_SIZE; 260 + if (xaddr == xaddr_prev + PAGE_SIZE) { 261 + command->rw_params.sizes[buffer_idx] += size_on_page; 262 + } else { 263 + ++buffer_idx; 264 + command->rw_params.ptrs[buffer_idx] = (u64)xaddr; 265 + command->rw_params.sizes[buffer_idx] = size_on_page; 266 + } 267 + xaddr_prev = xaddr; 268 + } 269 + command->rw_params.buffers_count = buffer_idx + 1; 270 + } 271 + 272 + static int transfer_max_buffers(struct goldfish_pipe *pipe, 273 + unsigned long address, unsigned long address_end, int is_write, 274 + unsigned long last_page, unsigned int last_page_size, 275 + s32 *consumed_size, int *status) 276 + { 277 + static struct page *pages[MAX_BUFFERS_PER_COMMAND]; 278 + unsigned long first_page = address & PAGE_MASK; 279 + unsigned int iter_last_page_size; 280 + int pages_count = pin_user_pages(first_page, last_page, 281 + last_page_size, is_write, 282 + pages, &iter_last_page_size); 283 + 284 + if (pages_count < 0) 285 + return pages_count; 286 + 287 + /* Serialize access to the pipe command buffers */ 399 288 if (mutex_lock_interruptible(&pipe->lock)) 400 289 return -ERESTARTSYS; 401 290 402 - address = (unsigned long)(void *)buffer; 291 + populate_rw_params(pages, pages_count, address, address_end, 292 + first_page, last_page, iter_last_page_size, is_write, 293 + pipe->command_buffer); 294 + 295 + /* Transfer the data */ 296 + *status = goldfish_cmd_locked(pipe, 297 + is_write ? PIPE_CMD_WRITE : PIPE_CMD_READ); 298 + 299 + *consumed_size = pipe->command_buffer->rw_params.consumed_size; 300 + 301 + release_user_pages(pages, pages_count, is_write, *consumed_size); 302 + 303 + mutex_unlock(&pipe->lock); 304 + 305 + return 0; 306 + } 307 + 308 + static int wait_for_host_signal(struct goldfish_pipe *pipe, int is_write) 309 + { 310 + u32 wakeBit = is_write ? BIT_WAKE_ON_WRITE : BIT_WAKE_ON_READ; 311 + 312 + set_bit(wakeBit, &pipe->flags); 313 + 314 + /* Tell the emulator we're going to wait for a wake event */ 315 + (void)goldfish_cmd(pipe, 316 + is_write ? PIPE_CMD_WAKE_ON_WRITE : PIPE_CMD_WAKE_ON_READ); 317 + 318 + while (test_bit(wakeBit, &pipe->flags)) { 319 + if (wait_event_interruptible( 320 + pipe->wake_queue, 321 + !test_bit(wakeBit, &pipe->flags))) 322 + return -ERESTARTSYS; 323 + 324 + if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) 325 + return -EIO; 326 + } 327 + 328 + return 0; 329 + } 330 + 331 + static ssize_t goldfish_pipe_read_write(struct file *filp, 332 + char __user *buffer, size_t bufflen, int is_write) 333 + { 334 + struct goldfish_pipe *pipe = filp->private_data; 335 + int count = 0, ret = -EINVAL; 336 + unsigned long address, address_end, last_page; 337 + unsigned int last_page_size; 338 + 339 + /* If the emulator already closed the pipe, no need to go further */ 340 + if (unlikely(test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))) 341 + return -EIO; 342 + /* Null reads or writes succeeds */ 343 + if (unlikely(bufflen == 0)) 344 + return 0; 345 + /* Check the buffer range for access */ 346 + if (unlikely(!access_ok(is_write ? VERIFY_WRITE : VERIFY_READ, 347 + buffer, bufflen))) 348 + return -EFAULT; 349 + 350 + address = (unsigned long)buffer; 403 351 address_end = address + bufflen; 352 + last_page = (address_end - 1) & PAGE_MASK; 353 + last_page_size = ((address_end - 1) & ~PAGE_MASK) + 1; 404 354 405 355 while (address < address_end) { 406 - unsigned long page_end = (address & PAGE_MASK) + PAGE_SIZE; 407 - unsigned long next = page_end < address_end ? page_end 408 - : address_end; 409 - unsigned long avail = next - address; 410 - int status, wakeBit; 411 - struct page *page; 356 + s32 consumed_size; 357 + int status; 412 358 413 - /* Either vaddr or paddr depending on the device version */ 414 - unsigned long xaddr; 415 - 416 - /* 417 - * We grab the pages on a page-by-page basis in case user 418 - * space gives us a potentially huge buffer but the read only 419 - * returns a small amount, then there's no need to pin that 420 - * much memory to the process. 421 - */ 422 - ret = get_user_pages_unlocked(address, 1, &page, 423 - is_write ? 0 : FOLL_WRITE); 359 + ret = transfer_max_buffers(pipe, address, address_end, is_write, 360 + last_page, last_page_size, &consumed_size, 361 + &status); 424 362 if (ret < 0) 425 363 break; 426 364 427 - if (dev->version) { 428 - /* Device version 1 or newer (qemu-android) expects the 429 - * physical address. 365 + if (consumed_size > 0) { 366 + /* No matter what's the status, we've transferred 367 + * something. 430 368 */ 431 - xaddr = page_to_phys(page) | (address & ~PAGE_MASK); 432 - } else { 433 - /* Device version 0 (classic emulator) expects the 434 - * virtual address. 435 - */ 436 - xaddr = address; 369 + count += consumed_size; 370 + address += consumed_size; 437 371 } 438 - 439 - /* Now, try to transfer the bytes in the current page */ 440 - spin_lock_irqsave(&dev->lock, irq_flags); 441 - if (access_with_param(dev, 442 - is_write ? CMD_WRITE_BUFFER : CMD_READ_BUFFER, 443 - xaddr, avail, pipe, &status)) { 444 - gf_write_ptr(pipe, dev->base + PIPE_REG_CHANNEL, 445 - dev->base + PIPE_REG_CHANNEL_HIGH); 446 - writel(avail, dev->base + PIPE_REG_SIZE); 447 - gf_write_ptr((void *)xaddr, 448 - dev->base + PIPE_REG_ADDRESS, 449 - dev->base + PIPE_REG_ADDRESS_HIGH); 450 - writel(is_write ? CMD_WRITE_BUFFER : CMD_READ_BUFFER, 451 - dev->base + PIPE_REG_COMMAND); 452 - status = readl(dev->base + PIPE_REG_STATUS); 453 - } 454 - spin_unlock_irqrestore(&dev->lock, irq_flags); 455 - 456 - if (status > 0 && !is_write) 457 - set_page_dirty(page); 458 - put_page(page); 459 - 460 - if (status > 0) { /* Correct transfer */ 461 - count += status; 462 - address += status; 372 + if (status > 0) 463 373 continue; 464 - } else if (status == 0) { /* EOF */ 374 + if (status == 0) { 375 + /* EOF */ 465 376 ret = 0; 466 377 break; 467 - } else if (status < 0 && count > 0) { 378 + } 379 + if (count > 0) { 468 380 /* 469 - * An error occurred and we already transferred 470 - * something on one of the previous pages. 381 + * An error occurred, but we already transferred 382 + * something on one of the previous iterations. 471 383 * Just return what we already copied and log this 472 384 * err. 473 - * 474 - * Note: This seems like an incorrect approach but 475 - * cannot change it until we check if any user space 476 - * ABI relies on this behavior. 477 385 */ 478 386 if (status != PIPE_ERROR_AGAIN) 479 - pr_info_ratelimited("goldfish_pipe: backend returned error %d on %s\n", 387 + pr_info_ratelimited("goldfish_pipe: backend error %d on %s\n", 480 388 status, is_write ? "write" : "read"); 481 - ret = 0; 482 389 break; 483 390 } 484 391 485 392 /* 486 - * If the error is not PIPE_ERROR_AGAIN, or if we are not in 393 + * If the error is not PIPE_ERROR_AGAIN, or if we are in 487 394 * non-blocking mode, just return the error code. 488 395 */ 489 396 if (status != PIPE_ERROR_AGAIN || ··· 510 381 break; 511 382 } 512 383 513 - /* 514 - * The backend blocked the read/write, wait until the backend 515 - * tells us it's ready to process more data. 516 - */ 517 - wakeBit = is_write ? BIT_WAKE_ON_WRITE : BIT_WAKE_ON_READ; 518 - set_bit(wakeBit, &pipe->flags); 519 - 520 - /* Tell the emulator we're going to wait for a wake event */ 521 - goldfish_cmd(pipe, 522 - is_write ? CMD_WAKE_ON_WRITE : CMD_WAKE_ON_READ); 523 - 524 - /* Unlock the pipe, then wait for the wake signal */ 525 - mutex_unlock(&pipe->lock); 526 - 527 - while (test_bit(wakeBit, &pipe->flags)) { 528 - if (wait_event_interruptible( 529 - pipe->wake_queue, 530 - !test_bit(wakeBit, &pipe->flags))) 531 - return -ERESTARTSYS; 532 - 533 - if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) 534 - return -EIO; 535 - } 536 - 537 - /* Try to re-acquire the lock */ 538 - if (mutex_lock_interruptible(&pipe->lock)) 539 - return -ERESTARTSYS; 384 + status = wait_for_host_signal(pipe, is_write); 385 + if (status < 0) 386 + return status; 540 387 } 541 - mutex_unlock(&pipe->lock); 542 388 543 - if (ret < 0) 544 - return ret; 545 - else 389 + if (count > 0) 546 390 return count; 391 + return ret; 547 392 } 548 393 549 394 static ssize_t goldfish_pipe_read(struct file *filp, char __user *buffer, 550 - size_t bufflen, loff_t *ppos) 395 + size_t bufflen, loff_t *ppos) 551 396 { 552 - return goldfish_pipe_read_write(filp, buffer, bufflen, 0); 397 + return goldfish_pipe_read_write(filp, buffer, bufflen, 398 + /* is_write */ 0); 553 399 } 554 400 555 401 static ssize_t goldfish_pipe_write(struct file *filp, 556 402 const char __user *buffer, size_t bufflen, 557 403 loff_t *ppos) 558 404 { 559 - return goldfish_pipe_read_write(filp, (char __user *)buffer, 560 - bufflen, 1); 405 + return goldfish_pipe_read_write(filp, 406 + /* cast away the const */(char __user *)buffer, bufflen, 407 + /* is_write */ 1); 561 408 } 562 - 563 409 564 410 static unsigned int goldfish_pipe_poll(struct file *filp, poll_table *wait) 565 411 { ··· 542 438 unsigned int mask = 0; 543 439 int status; 544 440 545 - mutex_lock(&pipe->lock); 546 - 547 441 poll_wait(filp, &pipe->wake_queue, wait); 548 442 549 - status = goldfish_cmd_status(pipe, CMD_POLL); 550 - 551 - mutex_unlock(&pipe->lock); 443 + status = goldfish_cmd(pipe, PIPE_CMD_POLL); 444 + if (status < 0) 445 + return -ERESTARTSYS; 552 446 553 447 if (status & PIPE_POLL_IN) 554 448 mask |= POLLIN | POLLRDNORM; 555 - 556 449 if (status & PIPE_POLL_OUT) 557 450 mask |= POLLOUT | POLLWRNORM; 558 - 559 451 if (status & PIPE_POLL_HUP) 560 452 mask |= POLLHUP; 561 - 562 453 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) 563 454 mask |= POLLERR; 564 455 565 456 return mask; 566 457 } 567 458 459 + static void signalled_pipes_add_locked(struct goldfish_pipe_dev *dev, 460 + u32 id, u32 flags) 461 + { 462 + struct goldfish_pipe *pipe; 463 + 464 + if (WARN_ON(id >= dev->pipes_capacity)) 465 + return; 466 + 467 + pipe = dev->pipes[id]; 468 + if (!pipe) 469 + return; 470 + pipe->signalled_flags |= flags; 471 + 472 + if (pipe->prev_signalled || pipe->next_signalled 473 + || dev->first_signalled_pipe == pipe) 474 + return; /* already in the list */ 475 + pipe->next_signalled = dev->first_signalled_pipe; 476 + if (dev->first_signalled_pipe) 477 + dev->first_signalled_pipe->prev_signalled = pipe; 478 + dev->first_signalled_pipe = pipe; 479 + } 480 + 481 + static void signalled_pipes_remove_locked(struct goldfish_pipe_dev *dev, 482 + struct goldfish_pipe *pipe) { 483 + if (pipe->prev_signalled) 484 + pipe->prev_signalled->next_signalled = pipe->next_signalled; 485 + if (pipe->next_signalled) 486 + pipe->next_signalled->prev_signalled = pipe->prev_signalled; 487 + if (pipe == dev->first_signalled_pipe) 488 + dev->first_signalled_pipe = pipe->next_signalled; 489 + pipe->prev_signalled = NULL; 490 + pipe->next_signalled = NULL; 491 + } 492 + 493 + static struct goldfish_pipe *signalled_pipes_pop_front( 494 + struct goldfish_pipe_dev *dev, int *wakes) 495 + { 496 + struct goldfish_pipe *pipe; 497 + unsigned long flags; 498 + 499 + spin_lock_irqsave(&dev->lock, flags); 500 + 501 + pipe = dev->first_signalled_pipe; 502 + if (pipe) { 503 + *wakes = pipe->signalled_flags; 504 + pipe->signalled_flags = 0; 505 + /* 506 + * This is an optimized version of 507 + * signalled_pipes_remove_locked() 508 + * - We want to make it as fast as possible to 509 + * wake the sleeping pipe operations faster. 510 + */ 511 + dev->first_signalled_pipe = pipe->next_signalled; 512 + if (dev->first_signalled_pipe) 513 + dev->first_signalled_pipe->prev_signalled = NULL; 514 + pipe->next_signalled = NULL; 515 + } 516 + 517 + spin_unlock_irqrestore(&dev->lock, flags); 518 + return pipe; 519 + } 520 + 521 + static void goldfish_interrupt_task(unsigned long unused) 522 + { 523 + struct goldfish_pipe_dev *dev = pipe_dev; 524 + /* Iterate over the signalled pipes and wake them one by one */ 525 + struct goldfish_pipe *pipe; 526 + int wakes; 527 + 528 + while ((pipe = signalled_pipes_pop_front(dev, &wakes)) != NULL) { 529 + if (wakes & PIPE_WAKE_CLOSED) { 530 + pipe->flags = 1 << BIT_CLOSED_ON_HOST; 531 + } else { 532 + if (wakes & PIPE_WAKE_READ) 533 + clear_bit(BIT_WAKE_ON_READ, &pipe->flags); 534 + if (wakes & PIPE_WAKE_WRITE) 535 + clear_bit(BIT_WAKE_ON_WRITE, &pipe->flags); 536 + } 537 + /* 538 + * wake_up_interruptible() implies a write barrier, so don't 539 + * explicitly add another one here. 540 + */ 541 + wake_up_interruptible(&pipe->wake_queue); 542 + } 543 + } 544 + DECLARE_TASKLET(goldfish_interrupt_tasklet, goldfish_interrupt_task, 0); 545 + 546 + /* 547 + * The general idea of the interrupt handling: 548 + * 549 + * 1. device raises an interrupt if there's at least one signalled pipe 550 + * 2. IRQ handler reads the signalled pipes and their count from the device 551 + * 3. device writes them into a shared buffer and returns the count 552 + * it only resets the IRQ if it has returned all signalled pipes, 553 + * otherwise it leaves it raised, so IRQ handler will be called 554 + * again for the next chunk 555 + * 4. IRQ handler adds all returned pipes to the device's signalled pipes list 556 + * 5. IRQ handler launches a tasklet to process the signalled pipes from the 557 + * list in a separate context 558 + */ 568 559 static irqreturn_t goldfish_pipe_interrupt(int irq, void *dev_id) 569 560 { 561 + u32 count; 562 + u32 i; 563 + unsigned long flags; 570 564 struct goldfish_pipe_dev *dev = dev_id; 571 - unsigned long irq_flags; 572 - int count = 0; 573 565 574 - /* 575 - * We're going to read from the emulator a list of (channel,flags) 576 - * pairs corresponding to the wake events that occurred on each 577 - * blocked pipe (i.e. channel). 578 - */ 579 - spin_lock_irqsave(&dev->lock, irq_flags); 580 - for (;;) { 581 - /* First read the channel, 0 means the end of the list */ 582 - struct goldfish_pipe *pipe; 583 - unsigned long wakes; 584 - unsigned long channel = 0; 566 + if (dev != pipe_dev) 567 + return IRQ_NONE; 585 568 586 - #ifdef CONFIG_64BIT 587 - channel = (u64)readl(dev->base + PIPE_REG_CHANNEL_HIGH) << 32; 569 + /* Request the signalled pipes from the device */ 570 + spin_lock_irqsave(&dev->lock, flags); 588 571 589 - if (channel == 0) 590 - break; 591 - #endif 592 - channel |= readl(dev->base + PIPE_REG_CHANNEL); 593 - 594 - if (channel == 0) 595 - break; 596 - 597 - /* Convert channel to struct pipe pointer + read wake flags */ 598 - wakes = readl(dev->base + PIPE_REG_WAKES); 599 - pipe = (struct goldfish_pipe *)(ptrdiff_t)channel; 600 - 601 - /* Did the emulator just closed a pipe? */ 602 - if (wakes & PIPE_WAKE_CLOSED) { 603 - set_bit(BIT_CLOSED_ON_HOST, &pipe->flags); 604 - wakes |= PIPE_WAKE_READ | PIPE_WAKE_WRITE; 605 - } 606 - if (wakes & PIPE_WAKE_READ) 607 - clear_bit(BIT_WAKE_ON_READ, &pipe->flags); 608 - if (wakes & PIPE_WAKE_WRITE) 609 - clear_bit(BIT_WAKE_ON_WRITE, &pipe->flags); 610 - 611 - wake_up_interruptible(&pipe->wake_queue); 612 - count++; 572 + count = readl(dev->base + PIPE_REG_GET_SIGNALLED); 573 + if (count == 0) { 574 + spin_unlock_irqrestore(&dev->lock, flags); 575 + return IRQ_NONE; 613 576 } 614 - spin_unlock_irqrestore(&dev->lock, irq_flags); 577 + if (count > MAX_SIGNALLED_PIPES) 578 + count = MAX_SIGNALLED_PIPES; 615 579 616 - return (count == 0) ? IRQ_NONE : IRQ_HANDLED; 580 + for (i = 0; i < count; ++i) 581 + signalled_pipes_add_locked(dev, 582 + dev->buffers->signalled_pipe_buffers[i].id, 583 + dev->buffers->signalled_pipe_buffers[i].flags); 584 + 585 + spin_unlock_irqrestore(&dev->lock, flags); 586 + 587 + tasklet_schedule(&goldfish_interrupt_tasklet); 588 + return IRQ_HANDLED; 589 + } 590 + 591 + static int get_free_pipe_id_locked(struct goldfish_pipe_dev *dev) 592 + { 593 + int id; 594 + 595 + for (id = 0; id < dev->pipes_capacity; ++id) 596 + if (!dev->pipes[id]) 597 + return id; 598 + 599 + { 600 + /* Reallocate the array */ 601 + u32 new_capacity = 2 * dev->pipes_capacity; 602 + struct goldfish_pipe **pipes = 603 + kcalloc(new_capacity, sizeof(*pipes), GFP_KERNEL); 604 + if (!pipes) 605 + return -ENOMEM; 606 + memcpy(pipes, dev->pipes, sizeof(*pipes) * dev->pipes_capacity); 607 + kfree(dev->pipes); 608 + dev->pipes = pipes; 609 + id = dev->pipes_capacity; 610 + dev->pipes_capacity = new_capacity; 611 + } 612 + return id; 617 613 } 618 614 619 615 /** 620 - * goldfish_pipe_open - open a channel to the AVD 616 + * goldfish_pipe_open - open a channel to the AVD 621 617 * @inode: inode of device 622 618 * @file: file struct of opener 623 619 * ··· 729 525 */ 730 526 static int goldfish_pipe_open(struct inode *inode, struct file *file) 731 527 { 732 - struct goldfish_pipe *pipe; 733 528 struct goldfish_pipe_dev *dev = pipe_dev; 734 - int32_t status; 529 + unsigned long flags; 530 + int id; 531 + int status; 735 532 736 533 /* Allocate new pipe kernel object */ 737 - pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); 534 + struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); 738 535 if (pipe == NULL) 739 536 return -ENOMEM; 740 537 ··· 744 539 init_waitqueue_head(&pipe->wake_queue); 745 540 746 541 /* 747 - * Now, tell the emulator we're opening a new pipe. We use the 748 - * pipe object's address as the channel identifier for simplicity. 542 + * Command buffer needs to be allocated on its own page to make sure 543 + * it is physically contiguous in host's address space. 749 544 */ 750 - 751 - status = goldfish_cmd_status(pipe, CMD_OPEN); 752 - if (status < 0) { 753 - kfree(pipe); 754 - return status; 545 + pipe->command_buffer = 546 + (struct goldfish_pipe_command *)__get_free_page(GFP_KERNEL); 547 + if (!pipe->command_buffer) { 548 + status = -ENOMEM; 549 + goto err_pipe; 755 550 } 756 551 552 + spin_lock_irqsave(&dev->lock, flags); 553 + 554 + id = get_free_pipe_id_locked(dev); 555 + if (id < 0) { 556 + status = id; 557 + goto err_id_locked; 558 + } 559 + 560 + dev->pipes[id] = pipe; 561 + pipe->id = id; 562 + pipe->command_buffer->id = id; 563 + 564 + /* Now tell the emulator we're opening a new pipe. */ 565 + dev->buffers->open_command_params.rw_params_max_count = 566 + MAX_BUFFERS_PER_COMMAND; 567 + dev->buffers->open_command_params.command_buffer_ptr = 568 + (u64)(unsigned long)__pa(pipe->command_buffer); 569 + status = goldfish_cmd_locked(pipe, PIPE_CMD_OPEN); 570 + spin_unlock_irqrestore(&dev->lock, flags); 571 + if (status < 0) 572 + goto err_cmd; 757 573 /* All is done, save the pipe into the file's private data field */ 758 574 file->private_data = pipe; 759 575 return 0; 576 + 577 + err_cmd: 578 + spin_lock_irqsave(&dev->lock, flags); 579 + dev->pipes[id] = NULL; 580 + err_id_locked: 581 + spin_unlock_irqrestore(&dev->lock, flags); 582 + free_page((unsigned long)pipe->command_buffer); 583 + err_pipe: 584 + kfree(pipe); 585 + return status; 760 586 } 761 587 762 588 static int goldfish_pipe_release(struct inode *inode, struct file *filp) 763 589 { 590 + unsigned long flags; 764 591 struct goldfish_pipe *pipe = filp->private_data; 592 + struct goldfish_pipe_dev *dev = pipe->dev; 765 593 766 594 /* The guest is closing the channel, so tell the emulator right now */ 767 - goldfish_cmd(pipe, CMD_CLOSE); 768 - kfree(pipe); 595 + (void)goldfish_cmd(pipe, PIPE_CMD_CLOSE); 596 + 597 + spin_lock_irqsave(&dev->lock, flags); 598 + dev->pipes[pipe->id] = NULL; 599 + signalled_pipes_remove_locked(dev, pipe); 600 + spin_unlock_irqrestore(&dev->lock, flags); 601 + 769 602 filp->private_data = NULL; 603 + free_page((unsigned long)pipe->command_buffer); 604 + kfree(pipe); 770 605 return 0; 771 606 } 772 607 ··· 819 574 .release = goldfish_pipe_release, 820 575 }; 821 576 822 - static struct miscdevice goldfish_pipe_device = { 577 + static struct miscdevice goldfish_pipe_dev = { 823 578 .minor = MISC_DYNAMIC_MINOR, 824 579 .name = "goldfish_pipe", 825 580 .fops = &goldfish_pipe_fops, 826 581 }; 582 + 583 + static int goldfish_pipe_device_init(struct platform_device *pdev) 584 + { 585 + char *page; 586 + struct goldfish_pipe_dev *dev = pipe_dev; 587 + int err = devm_request_irq(&pdev->dev, dev->irq, 588 + goldfish_pipe_interrupt, 589 + IRQF_SHARED, "goldfish_pipe", dev); 590 + if (err) { 591 + dev_err(&pdev->dev, "unable to allocate IRQ for v2\n"); 592 + return err; 593 + } 594 + 595 + err = misc_register(&goldfish_pipe_dev); 596 + if (err) { 597 + dev_err(&pdev->dev, "unable to register v2 device\n"); 598 + return err; 599 + } 600 + 601 + dev->first_signalled_pipe = NULL; 602 + dev->pipes_capacity = INITIAL_PIPES_CAPACITY; 603 + dev->pipes = kcalloc(dev->pipes_capacity, sizeof(*dev->pipes), 604 + GFP_KERNEL); 605 + if (!dev->pipes) 606 + return -ENOMEM; 607 + 608 + /* 609 + * We're going to pass two buffers, open_command_params and 610 + * signalled_pipe_buffers, to the host. This means each of those buffers 611 + * needs to be contained in a single physical page. The easiest choice 612 + * is to just allocate a page and place the buffers in it. 613 + */ 614 + if (WARN_ON(sizeof(*dev->buffers) > PAGE_SIZE)) 615 + return -ENOMEM; 616 + 617 + page = (char *)__get_free_page(GFP_KERNEL); 618 + if (!page) { 619 + kfree(dev->pipes); 620 + return -ENOMEM; 621 + } 622 + dev->buffers = (struct goldfish_pipe_dev_buffers *)page; 623 + 624 + /* Send the buffer addresses to the host */ 625 + { 626 + u64 paddr = __pa(&dev->buffers->signalled_pipe_buffers); 627 + 628 + writel((u32)(unsigned long)(paddr >> 32), 629 + dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH); 630 + writel((u32)(unsigned long)paddr, 631 + dev->base + PIPE_REG_SIGNAL_BUFFER); 632 + writel((u32)MAX_SIGNALLED_PIPES, 633 + dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT); 634 + 635 + paddr = __pa(&dev->buffers->open_command_params); 636 + writel((u32)(unsigned long)(paddr >> 32), 637 + dev->base + PIPE_REG_OPEN_BUFFER_HIGH); 638 + writel((u32)(unsigned long)paddr, 639 + dev->base + PIPE_REG_OPEN_BUFFER); 640 + } 641 + return 0; 642 + } 643 + 644 + static void goldfish_pipe_device_deinit(struct platform_device *pdev) 645 + { 646 + struct goldfish_pipe_dev *dev = pipe_dev; 647 + 648 + misc_deregister(&goldfish_pipe_dev); 649 + kfree(dev->pipes); 650 + free_page((unsigned long)dev->buffers); 651 + } 827 652 828 653 static int goldfish_pipe_probe(struct platform_device *pdev) 829 654 { 830 655 int err; 831 656 struct resource *r; 832 657 struct goldfish_pipe_dev *dev = pipe_dev; 658 + 659 + if (WARN_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE)) 660 + return -ENOMEM; 833 661 834 662 /* not thread safe, but this should not happen */ 835 663 WARN_ON(dev->base != NULL); ··· 927 609 } 928 610 dev->irq = r->start; 929 611 930 - err = devm_request_irq(&pdev->dev, dev->irq, goldfish_pipe_interrupt, 931 - IRQF_SHARED, "goldfish_pipe", dev); 932 - if (err) { 933 - dev_err(&pdev->dev, "unable to allocate IRQ\n"); 934 - goto error; 935 - } 936 - 937 - err = misc_register(&goldfish_pipe_device); 938 - if (err) { 939 - dev_err(&pdev->dev, "unable to register device\n"); 940 - goto error; 941 - } 942 - setup_access_params_addr(pdev, dev); 943 - 944 - /* Although the pipe device in the classic Android emulator does not 945 - * recognize the 'version' register, it won't treat this as an error 946 - * either and will simply return 0, which is fine. 612 + /* 613 + * Exchange the versions with the host device 614 + * 615 + * Note: v1 driver used to not report its version, so we write it before 616 + * reading device version back: this allows the host implementation to 617 + * detect the old driver (if there was no version write before read). 947 618 */ 619 + writel((u32)PIPE_DRIVER_VERSION, dev->base + PIPE_REG_VERSION); 948 620 dev->version = readl(dev->base + PIPE_REG_VERSION); 949 - return 0; 621 + if (WARN_ON(dev->version < PIPE_CURRENT_DEVICE_VERSION)) 622 + return -EINVAL; 623 + 624 + err = goldfish_pipe_device_init(pdev); 625 + if (!err) 626 + return 0; 950 627 951 628 error: 952 629 dev->base = NULL; ··· 951 638 static int goldfish_pipe_remove(struct platform_device *pdev) 952 639 { 953 640 struct goldfish_pipe_dev *dev = pipe_dev; 954 - misc_deregister(&goldfish_pipe_device); 641 + goldfish_pipe_device_deinit(pdev); 955 642 dev->base = NULL; 956 643 return 0; 957 644 } ··· 968 655 }; 969 656 MODULE_DEVICE_TABLE(of, goldfish_pipe_of_match); 970 657 971 - static struct platform_driver goldfish_pipe = { 658 + static struct platform_driver goldfish_pipe_driver = { 972 659 .probe = goldfish_pipe_probe, 973 660 .remove = goldfish_pipe_remove, 974 661 .driver = { 975 662 .name = "goldfish_pipe", 976 - .owner = THIS_MODULE, 977 663 .of_match_table = goldfish_pipe_of_match, 978 664 .acpi_match_table = ACPI_PTR(goldfish_pipe_acpi_match), 979 665 } 980 666 }; 981 667 982 - module_platform_driver(goldfish_pipe); 668 + module_platform_driver(goldfish_pipe_driver); 983 669 MODULE_AUTHOR("David Turner <digit@google.com>"); 984 670 MODULE_LICENSE("GPL");
+92 -31
drivers/pps/pps.c
··· 64 64 return fasync_helper(fd, file, on, &pps->async_queue); 65 65 } 66 66 67 + static int pps_cdev_pps_fetch(struct pps_device *pps, struct pps_fdata *fdata) 68 + { 69 + unsigned int ev = pps->last_ev; 70 + int err = 0; 71 + 72 + /* Manage the timeout */ 73 + if (fdata->timeout.flags & PPS_TIME_INVALID) 74 + err = wait_event_interruptible(pps->queue, 75 + ev != pps->last_ev); 76 + else { 77 + unsigned long ticks; 78 + 79 + dev_dbg(pps->dev, "timeout %lld.%09d\n", 80 + (long long) fdata->timeout.sec, 81 + fdata->timeout.nsec); 82 + ticks = fdata->timeout.sec * HZ; 83 + ticks += fdata->timeout.nsec / (NSEC_PER_SEC / HZ); 84 + 85 + if (ticks != 0) { 86 + err = wait_event_interruptible_timeout( 87 + pps->queue, 88 + ev != pps->last_ev, 89 + ticks); 90 + if (err == 0) 91 + return -ETIMEDOUT; 92 + } 93 + } 94 + 95 + /* Check for pending signals */ 96 + if (err == -ERESTARTSYS) { 97 + dev_dbg(pps->dev, "pending signal caught\n"); 98 + return -EINTR; 99 + } 100 + 101 + return 0; 102 + } 103 + 67 104 static long pps_cdev_ioctl(struct file *file, 68 105 unsigned int cmd, unsigned long arg) 69 106 { ··· 181 144 182 145 case PPS_FETCH: { 183 146 struct pps_fdata fdata; 184 - unsigned int ev; 185 147 186 148 dev_dbg(pps->dev, "PPS_FETCH\n"); 187 149 ··· 188 152 if (err) 189 153 return -EFAULT; 190 154 191 - ev = pps->last_ev; 192 - 193 - /* Manage the timeout */ 194 - if (fdata.timeout.flags & PPS_TIME_INVALID) 195 - err = wait_event_interruptible(pps->queue, 196 - ev != pps->last_ev); 197 - else { 198 - unsigned long ticks; 199 - 200 - dev_dbg(pps->dev, "timeout %lld.%09d\n", 201 - (long long) fdata.timeout.sec, 202 - fdata.timeout.nsec); 203 - ticks = fdata.timeout.sec * HZ; 204 - ticks += fdata.timeout.nsec / (NSEC_PER_SEC / HZ); 205 - 206 - if (ticks != 0) { 207 - err = wait_event_interruptible_timeout( 208 - pps->queue, 209 - ev != pps->last_ev, 210 - ticks); 211 - if (err == 0) 212 - return -ETIMEDOUT; 213 - } 214 - } 215 - 216 - /* Check for pending signals */ 217 - if (err == -ERESTARTSYS) { 218 - dev_dbg(pps->dev, "pending signal caught\n"); 219 - return -EINTR; 220 - } 155 + err = pps_cdev_pps_fetch(pps, &fdata); 156 + if (err) 157 + return err; 221 158 222 159 /* Return the fetched timestamp */ 223 160 spin_lock_irq(&pps->lock); ··· 251 242 return 0; 252 243 } 253 244 245 + #ifdef CONFIG_COMPAT 246 + static long pps_cdev_compat_ioctl(struct file *file, 247 + unsigned int cmd, unsigned long arg) 248 + { 249 + struct pps_device *pps = file->private_data; 250 + void __user *uarg = (void __user *) arg; 251 + 252 + cmd = _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(void *)); 253 + 254 + if (cmd == PPS_FETCH) { 255 + struct pps_fdata_compat compat; 256 + struct pps_fdata fdata; 257 + int err; 258 + 259 + dev_dbg(pps->dev, "PPS_FETCH\n"); 260 + 261 + err = copy_from_user(&compat, uarg, sizeof(struct pps_fdata_compat)); 262 + if (err) 263 + return -EFAULT; 264 + 265 + memcpy(&fdata.timeout, &compat.timeout, 266 + sizeof(struct pps_ktime_compat)); 267 + 268 + err = pps_cdev_pps_fetch(pps, &fdata); 269 + if (err) 270 + return err; 271 + 272 + /* Return the fetched timestamp */ 273 + spin_lock_irq(&pps->lock); 274 + 275 + compat.info.assert_sequence = pps->assert_sequence; 276 + compat.info.clear_sequence = pps->clear_sequence; 277 + compat.info.current_mode = pps->current_mode; 278 + 279 + memcpy(&compat.info.assert_tu, &pps->assert_tu, 280 + sizeof(struct pps_ktime_compat)); 281 + memcpy(&compat.info.clear_tu, &pps->clear_tu, 282 + sizeof(struct pps_ktime_compat)); 283 + 284 + spin_unlock_irq(&pps->lock); 285 + 286 + return copy_to_user(uarg, &compat, 287 + sizeof(struct pps_fdata_compat)) ? -EFAULT : 0; 288 + } 289 + 290 + return pps_cdev_ioctl(file, cmd, arg); 291 + } 292 + #else 293 + #define pps_cdev_compat_ioctl NULL 294 + #endif 295 + 254 296 static int pps_cdev_open(struct inode *inode, struct file *file) 255 297 { 256 298 struct pps_device *pps = container_of(inode->i_cdev, ··· 328 268 .llseek = no_llseek, 329 269 .poll = pps_cdev_poll, 330 270 .fasync = pps_cdev_fasync, 271 + .compat_ioctl = pps_cdev_compat_ioctl, 331 272 .unlocked_ioctl = pps_cdev_ioctl, 332 273 .open = pps_cdev_open, 333 274 .release = pps_cdev_release,
+8 -16
drivers/rapidio/devices/rio_mport_cdev.c
··· 2444 2444 mutex_init(&md->buf_mutex); 2445 2445 mutex_init(&md->file_mutex); 2446 2446 INIT_LIST_HEAD(&md->file_list); 2447 - cdev_init(&md->cdev, &mport_fops); 2448 - md->cdev.owner = THIS_MODULE; 2449 - ret = cdev_add(&md->cdev, MKDEV(MAJOR(dev_number), mport->id), 1); 2450 - if (ret < 0) { 2451 - kfree(md); 2452 - rmcd_error("Unable to register a device, err=%d", ret); 2453 - return NULL; 2454 - } 2455 2447 2456 - md->dev.devt = md->cdev.dev; 2448 + device_initialize(&md->dev); 2449 + md->dev.devt = MKDEV(MAJOR(dev_number), mport->id); 2457 2450 md->dev.class = dev_class; 2458 2451 md->dev.parent = &mport->dev; 2459 2452 md->dev.release = mport_device_release; 2460 2453 dev_set_name(&md->dev, DEV_NAME "%d", mport->id); 2461 2454 atomic_set(&md->active, 1); 2462 2455 2463 - ret = device_register(&md->dev); 2456 + cdev_init(&md->cdev, &mport_fops); 2457 + md->cdev.owner = THIS_MODULE; 2458 + 2459 + ret = cdev_device_add(&md->cdev, &md->dev); 2464 2460 if (ret) { 2465 2461 rmcd_error("Failed to register mport %d (err=%d)", 2466 2462 mport->id, ret); 2467 2463 goto err_cdev; 2468 2464 } 2469 - 2470 - get_device(&md->dev); 2471 2465 2472 2466 INIT_LIST_HEAD(&md->doorbells); 2473 2467 spin_lock_init(&md->db_lock); ··· 2507 2513 return md; 2508 2514 2509 2515 err_cdev: 2510 - cdev_del(&md->cdev); 2511 - kfree(md); 2516 + put_device(&md->dev); 2512 2517 return NULL; 2513 2518 } 2514 2519 ··· 2571 2578 atomic_set(&md->active, 0); 2572 2579 mport_cdev_terminate_dma(md); 2573 2580 rio_del_mport_pw_handler(md->mport, md, rio_mport_pw_handler); 2574 - cdev_del(&(md->cdev)); 2581 + cdev_device_del(&md->cdev, &md->dev); 2575 2582 mport_cdev_kill_fasync(md); 2576 2583 2577 2584 flush_workqueue(dma_wq); ··· 2596 2603 2597 2604 rio_release_inb_dbell(md->mport, 0, 0x0fff); 2598 2605 2599 - device_unregister(&md->dev); 2600 2606 put_device(&md->dev); 2601 2607 } 2602 2608
+32 -42
drivers/rapidio/rio-sysfs.c
··· 108 108 &dev_attr_lprev.attr, 109 109 &dev_attr_destid.attr, 110 110 &dev_attr_modalias.attr, 111 - NULL, 112 - }; 113 111 114 - static const struct attribute_group rio_dev_group = { 115 - .attrs = rio_dev_attrs, 116 - }; 117 - 118 - const struct attribute_group *rio_dev_groups[] = { 119 - &rio_dev_group, 112 + /* Switch-only attributes */ 113 + &dev_attr_routes.attr, 114 + &dev_attr_lnext.attr, 115 + &dev_attr_hopcount.attr, 120 116 NULL, 121 117 }; 122 118 ··· 255 259 .write = rio_write_config, 256 260 }; 257 261 258 - /** 259 - * rio_create_sysfs_dev_files - create RIO specific sysfs files 260 - * @rdev: device whose entries should be created 261 - * 262 - * Create files when @rdev is added to sysfs. 263 - */ 264 - int rio_create_sysfs_dev_files(struct rio_dev *rdev) 262 + static struct bin_attribute *rio_dev_bin_attrs[] = { 263 + &rio_config_attr, 264 + NULL, 265 + }; 266 + 267 + static umode_t rio_dev_is_attr_visible(struct kobject *kobj, 268 + struct attribute *attr, int n) 265 269 { 266 - int err = 0; 270 + struct rio_dev *rdev = to_rio_dev(kobj_to_dev(kobj)); 271 + umode_t mode = attr->mode; 267 272 268 - err = device_create_bin_file(&rdev->dev, &rio_config_attr); 269 - 270 - if (!err && (rdev->pef & RIO_PEF_SWITCH)) { 271 - err |= device_create_file(&rdev->dev, &dev_attr_routes); 272 - err |= device_create_file(&rdev->dev, &dev_attr_lnext); 273 - err |= device_create_file(&rdev->dev, &dev_attr_hopcount); 273 + if (!(rdev->pef & RIO_PEF_SWITCH) && 274 + (attr == &dev_attr_routes.attr || 275 + attr == &dev_attr_lnext.attr || 276 + attr == &dev_attr_hopcount.attr)) { 277 + /* 278 + * Hide switch-specific attributes for a non-switch device. 279 + */ 280 + mode = 0; 274 281 } 275 282 276 - if (err) 277 - pr_warning("RIO: Failed to create attribute file(s) for %s\n", 278 - rio_name(rdev)); 279 - 280 - return err; 283 + return mode; 281 284 } 282 285 283 - /** 284 - * rio_remove_sysfs_dev_files - cleanup RIO specific sysfs files 285 - * @rdev: device whose entries we should free 286 - * 287 - * Cleanup when @rdev is removed from sysfs. 288 - */ 289 - void rio_remove_sysfs_dev_files(struct rio_dev *rdev) 290 - { 291 - device_remove_bin_file(&rdev->dev, &rio_config_attr); 292 - if (rdev->pef & RIO_PEF_SWITCH) { 293 - device_remove_file(&rdev->dev, &dev_attr_routes); 294 - device_remove_file(&rdev->dev, &dev_attr_lnext); 295 - device_remove_file(&rdev->dev, &dev_attr_hopcount); 296 - } 297 - } 286 + static const struct attribute_group rio_dev_group = { 287 + .attrs = rio_dev_attrs, 288 + .is_visible = rio_dev_is_attr_visible, 289 + .bin_attrs = rio_dev_bin_attrs, 290 + }; 291 + 292 + const struct attribute_group *rio_dev_groups[] = { 293 + &rio_dev_group, 294 + NULL, 295 + }; 298 296 299 297 static ssize_t bus_scan_store(struct bus_type *bus, const char *buf, 300 298 size_t count)
-3
drivers/rapidio/rio.c
··· 192 192 } 193 193 spin_unlock(&rio_global_list_lock); 194 194 195 - rio_create_sysfs_dev_files(rdev); 196 - 197 195 return 0; 198 196 } 199 197 EXPORT_SYMBOL_GPL(rio_add_device); ··· 218 220 } 219 221 } 220 222 spin_unlock(&rio_global_list_lock); 221 - rio_remove_sysfs_dev_files(rdev); 222 223 device_unregister(&rdev->dev); 223 224 } 224 225 EXPORT_SYMBOL_GPL(rio_del_device);
-2
drivers/rapidio/rio.h
··· 27 27 u8 hopcount, u32 from); 28 28 extern int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, 29 29 u8 hopcount); 30 - extern int rio_create_sysfs_dev_files(struct rio_dev *rdev); 31 - extern void rio_remove_sysfs_dev_files(struct rio_dev *rdev); 32 30 extern int rio_lock_device(struct rio_mport *port, u16 destid, 33 31 u8 hopcount, int wait_ms); 34 32 extern int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount);
+10 -4
drivers/rtc/class.c
··· 195 195 goto exit_ida; 196 196 } 197 197 198 + device_initialize(&rtc->dev); 199 + 198 200 rtc->id = id; 199 201 rtc->ops = ops; 200 202 rtc->owner = owner; ··· 235 233 236 234 rtc_dev_prepare(rtc); 237 235 238 - err = device_register(&rtc->dev); 236 + err = cdev_device_add(&rtc->char_dev, &rtc->dev); 239 237 if (err) { 238 + dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", 239 + rtc->name, MAJOR(rtc->dev.devt), rtc->id); 240 + 240 241 /* This will free both memory and the ID */ 241 242 put_device(&rtc->dev); 242 243 goto exit; 244 + } else { 245 + dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, 246 + MAJOR(rtc->dev.devt), rtc->id); 243 247 } 244 248 245 - rtc_dev_add_device(rtc); 246 249 rtc_proc_add_device(rtc); 247 250 248 251 dev_info(dev, "rtc core: registered %s as %s\n", ··· 278 271 * Remove innards of this RTC, then disable it, before 279 272 * letting any rtc_class_open() users access it again 280 273 */ 281 - rtc_dev_del_device(rtc); 282 274 rtc_proc_del_device(rtc); 283 - device_del(&rtc->dev); 275 + cdev_device_del(&rtc->char_dev, &rtc->dev); 284 276 rtc->ops = NULL; 285 277 mutex_unlock(&rtc->ops_lock); 286 278 put_device(&rtc->dev);
-10
drivers/rtc/rtc-core.h
··· 3 3 extern void __init rtc_dev_init(void); 4 4 extern void __exit rtc_dev_exit(void); 5 5 extern void rtc_dev_prepare(struct rtc_device *rtc); 6 - extern void rtc_dev_add_device(struct rtc_device *rtc); 7 - extern void rtc_dev_del_device(struct rtc_device *rtc); 8 6 9 7 #else 10 8 ··· 15 17 } 16 18 17 19 static inline void rtc_dev_prepare(struct rtc_device *rtc) 18 - { 19 - } 20 - 21 - static inline void rtc_dev_add_device(struct rtc_device *rtc) 22 - { 23 - } 24 - 25 - static inline void rtc_dev_del_device(struct rtc_device *rtc) 26 20 { 27 21 } 28 22
-17
drivers/rtc/rtc-dev.c
··· 477 477 478 478 cdev_init(&rtc->char_dev, &rtc_dev_fops); 479 479 rtc->char_dev.owner = rtc->owner; 480 - rtc->char_dev.kobj.parent = &rtc->dev.kobj; 481 - } 482 - 483 - void rtc_dev_add_device(struct rtc_device *rtc) 484 - { 485 - if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1)) 486 - dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", 487 - rtc->name, MAJOR(rtc_devt), rtc->id); 488 - else 489 - dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, 490 - MAJOR(rtc_devt), rtc->id); 491 - } 492 - 493 - void rtc_dev_del_device(struct rtc_device *rtc) 494 - { 495 - if (rtc->dev.devt) 496 - cdev_del(&rtc->char_dev); 497 480 } 498 481 499 482 void __init rtc_dev_init(void)
+21 -38
drivers/scsi/osd/osd_uld.c
··· 400 400 401 401 kfree(oud->odi.osdname); 402 402 403 - if (oud->cdev.owner) 404 - cdev_del(&oud->cdev); 405 - 406 403 osd_dev_fini(&oud->od); 407 404 scsi_device_put(scsi_device); 408 405 ··· 408 411 409 412 if (oud->disk) 410 413 put_disk(oud->disk); 411 - ida_remove(&osd_minor_ida, oud->minor); 412 414 413 415 kfree(oud); 414 416 } ··· 442 446 if (NULL == oud) 443 447 goto err_retract_minor; 444 448 449 + /* class device member */ 450 + device_initialize(&oud->class_dev); 445 451 dev_set_drvdata(dev, oud); 446 452 oud->minor = minor; 453 + oud->class_dev.devt = MKDEV(SCSI_OSD_MAJOR, oud->minor); 454 + oud->class_dev.class = &osd_uld_class; 455 + oud->class_dev.parent = dev; 456 + oud->class_dev.release = __remove; 457 + 458 + /* hold one more reference to the scsi_device that will get released 459 + * in __release, in case a logout is happening while fs is mounted 460 + */ 461 + if (scsi_device_get(scsi_device)) 462 + goto err_retract_minor; 463 + osd_dev_init(&oud->od, scsi_device); 447 464 448 465 /* allocate a disk and set it up */ 449 466 /* FIXME: do we need this since sg has already done that */ ··· 470 461 sprintf(disk->disk_name, "osd%d", oud->minor); 471 462 oud->disk = disk; 472 463 473 - /* hold one more reference to the scsi_device that will get released 474 - * in __release, in case a logout is happening while fs is mounted 475 - */ 476 - if (scsi_device_get(scsi_device)) 477 - goto err_put_disk; 478 - osd_dev_init(&oud->od, scsi_device); 479 - 480 464 /* Detect the OSD Version */ 481 465 error = __detect_osd(oud); 482 466 if (error) { 483 467 OSD_ERR("osd detection failed, non-compatible OSD device\n"); 484 - goto err_put_sdev; 468 + goto err_free_osd; 485 469 } 486 470 487 471 /* init the char-device for communication with user-mode */ 488 472 cdev_init(&oud->cdev, &osd_fops); 489 473 oud->cdev.owner = THIS_MODULE; 490 - error = cdev_add(&oud->cdev, 491 - MKDEV(SCSI_OSD_MAJOR, oud->minor), 1); 492 - if (error) { 493 - OSD_ERR("cdev_add failed\n"); 494 - goto err_put_disk; 495 - } 496 474 497 - /* class device member */ 498 - oud->class_dev.devt = oud->cdev.dev; 499 - oud->class_dev.class = &osd_uld_class; 500 - oud->class_dev.parent = dev; 501 - oud->class_dev.release = __remove; 502 475 error = dev_set_name(&oud->class_dev, "%s", disk->disk_name); 503 476 if (error) { 504 477 OSD_ERR("dev_set_name failed => %d\n", error); 505 - goto err_put_cdev; 478 + goto err_free_osd; 506 479 } 507 480 508 - error = device_register(&oud->class_dev); 481 + error = cdev_device_add(&oud->cdev, &oud->class_dev); 509 482 if (error) { 510 483 OSD_ERR("device_register failed => %d\n", error); 511 - goto err_put_cdev; 484 + goto err_free_osd; 512 485 } 513 - 514 - get_device(&oud->class_dev); 515 486 516 487 OSD_INFO("osd_probe %s\n", disk->disk_name); 517 488 return 0; 518 489 519 - err_put_cdev: 520 - cdev_del(&oud->cdev); 521 - err_put_sdev: 522 - scsi_device_put(scsi_device); 523 - err_put_disk: 524 - put_disk(disk); 525 490 err_free_osd: 526 - dev_set_drvdata(dev, NULL); 527 - kfree(oud); 491 + put_device(&oud->class_dev); 528 492 err_retract_minor: 529 493 ida_remove(&osd_minor_ida, minor); 530 494 return error; ··· 513 531 dev, oud->od.scsi_device, scsi_device); 514 532 } 515 533 516 - device_unregister(&oud->class_dev); 517 - 534 + cdev_device_del(&oud->cdev, &oud->class_dev); 535 + ida_remove(&osd_minor_ida, oud->minor); 518 536 put_device(&oud->class_dev); 537 + 519 538 return 0; 520 539 } 521 540
+1 -1
drivers/uio/uio.c
··· 66 66 67 67 static ssize_t map_offset_show(struct uio_mem *mem, char *buf) 68 68 { 69 - return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & ~PAGE_MASK); 69 + return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs); 70 70 } 71 71 72 72 struct map_sysfs_entry {
+22 -26
drivers/uio/uio_mf624.c
··· 127 127 return 0; 128 128 } 129 129 130 + static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, const char *name) 131 + { 132 + resource_size_t start = pci_resource_start(dev, bar); 133 + resource_size_t len = pci_resource_len(dev, bar); 134 + 135 + mem->name = name; 136 + mem->addr = start & PAGE_MASK; 137 + mem->offs = start & ~PAGE_MASK; 138 + if (!mem->addr) 139 + return -ENODEV; 140 + mem->size = ((start & ~PAGE_MASK) + len + PAGE_SIZE - 1) & PAGE_MASK; 141 + mem->memtype = UIO_MEM_PHYS; 142 + mem->internal_addr = pci_ioremap_bar(dev, bar); 143 + if (!mem->internal_addr) 144 + return -ENODEV; 145 + return 0; 146 + } 147 + 130 148 static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 131 149 { 132 150 struct uio_info *info; ··· 165 147 /* Note: Datasheet says device uses BAR0, BAR1, BAR2 -- do not trust it */ 166 148 167 149 /* BAR0 */ 168 - info->mem[0].name = "PCI chipset, interrupts, status " 169 - "bits, special functions"; 170 - info->mem[0].addr = pci_resource_start(dev, 0); 171 - if (!info->mem[0].addr) 150 + if (mf624_setup_mem(dev, 0, &info->mem[0], "PCI chipset, interrupts, status " 151 + "bits, special functions")) 172 152 goto out_release; 173 - info->mem[0].size = pci_resource_len(dev, 0); 174 - info->mem[0].memtype = UIO_MEM_PHYS; 175 - info->mem[0].internal_addr = pci_ioremap_bar(dev, 0); 176 - if (!info->mem[0].internal_addr) 177 - goto out_release; 178 - 179 153 /* BAR2 */ 180 - info->mem[1].name = "ADC, DAC, DIO"; 181 - info->mem[1].addr = pci_resource_start(dev, 2); 182 - if (!info->mem[1].addr) 183 - goto out_unmap0; 184 - info->mem[1].size = pci_resource_len(dev, 2); 185 - info->mem[1].memtype = UIO_MEM_PHYS; 186 - info->mem[1].internal_addr = pci_ioremap_bar(dev, 2); 187 - if (!info->mem[1].internal_addr) 154 + if (mf624_setup_mem(dev, 2, &info->mem[1], "ADC, DAC, DIO")) 188 155 goto out_unmap0; 189 156 190 157 /* BAR4 */ 191 - info->mem[2].name = "Counter/timer chip"; 192 - info->mem[2].addr = pci_resource_start(dev, 4); 193 - if (!info->mem[2].addr) 194 - goto out_unmap1; 195 - info->mem[2].size = pci_resource_len(dev, 4); 196 - info->mem[2].memtype = UIO_MEM_PHYS; 197 - info->mem[2].internal_addr = pci_ioremap_bar(dev, 4); 198 - if (!info->mem[2].internal_addr) 158 + if (mf624_setup_mem(dev, 4, &info->mem[2], "Counter/timer chip")) 199 159 goto out_unmap1; 200 160 201 161 info->irq = dev->irq;
+438 -31
drivers/vme/vme.c
··· 76 76 } 77 77 } 78 78 79 - /* 79 + /** 80 + * vme_free_consistent - Allocate contiguous memory. 81 + * @resource: Pointer to VME resource. 82 + * @size: Size of allocation required. 83 + * @dma: Pointer to variable to store physical address of allocation. 84 + * 80 85 * Allocate a contiguous block of memory for use by the driver. This is used to 81 86 * create the buffers for the slave windows. 87 + * 88 + * Return: Virtual address of allocation on success, NULL on failure. 82 89 */ 83 90 void *vme_alloc_consistent(struct vme_resource *resource, size_t size, 84 91 dma_addr_t *dma) ··· 118 111 } 119 112 EXPORT_SYMBOL(vme_alloc_consistent); 120 113 121 - /* 122 - * Free previously allocated contiguous block of memory. 114 + /** 115 + * vme_free_consistent - Free previously allocated memory. 116 + * @resource: Pointer to VME resource. 117 + * @size: Size of allocation to free. 118 + * @vaddr: Virtual address of allocation. 119 + * @dma: Physical address of allocation. 120 + * 121 + * Free previously allocated block of contiguous memory. 123 122 */ 124 123 void vme_free_consistent(struct vme_resource *resource, size_t size, 125 124 void *vaddr, dma_addr_t dma) ··· 158 145 } 159 146 EXPORT_SYMBOL(vme_free_consistent); 160 147 148 + /** 149 + * vme_get_size - Helper function returning size of a VME window 150 + * @resource: Pointer to VME slave or master resource. 151 + * 152 + * Determine the size of the VME window provided. This is a helper 153 + * function, wrappering the call to vme_master_get or vme_slave_get 154 + * depending on the type of window resource handed to it. 155 + * 156 + * Return: Size of the window on success, zero on failure. 157 + */ 161 158 size_t vme_get_size(struct vme_resource *resource) 162 159 { 163 160 int enabled, retval; ··· 282 259 return 0; 283 260 } 284 261 285 - /* 286 - * Request a slave image with specific attributes, return some unique 287 - * identifier. 262 + /** 263 + * vme_slave_request - Request a VME slave window resource. 264 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 265 + * @address: Required VME address space. 266 + * @cycle: Required VME data transfer cycle type. 267 + * 268 + * Request use of a VME window resource capable of being set for the requested 269 + * address space and data transfer cycle. 270 + * 271 + * Return: Pointer to VME resource on success, NULL on failure. 288 272 */ 289 273 struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address, 290 274 u32 cycle) ··· 357 327 } 358 328 EXPORT_SYMBOL(vme_slave_request); 359 329 330 + /** 331 + * vme_slave_set - Set VME slave window configuration. 332 + * @resource: Pointer to VME slave resource. 333 + * @enabled: State to which the window should be configured. 334 + * @vme_base: Base address for the window. 335 + * @size: Size of the VME window. 336 + * @buf_base: Based address of buffer used to provide VME slave window storage. 337 + * @aspace: VME address space for the VME window. 338 + * @cycle: VME data transfer cycle type for the VME window. 339 + * 340 + * Set configuration for provided VME slave window. 341 + * 342 + * Return: Zero on success, -EINVAL if operation is not supported on this 343 + * device, if an invalid resource has been provided or invalid 344 + * attributes are provided. Hardware specific errors may also be 345 + * returned. 346 + */ 360 347 int vme_slave_set(struct vme_resource *resource, int enabled, 361 348 unsigned long long vme_base, unsigned long long size, 362 349 dma_addr_t buf_base, u32 aspace, u32 cycle) ··· 409 362 } 410 363 EXPORT_SYMBOL(vme_slave_set); 411 364 365 + /** 366 + * vme_slave_get - Retrieve VME slave window configuration. 367 + * @resource: Pointer to VME slave resource. 368 + * @enabled: Pointer to variable for storing state. 369 + * @vme_base: Pointer to variable for storing window base address. 370 + * @size: Pointer to variable for storing window size. 371 + * @buf_base: Pointer to variable for storing slave buffer base address. 372 + * @aspace: Pointer to variable for storing VME address space. 373 + * @cycle: Pointer to variable for storing VME data transfer cycle type. 374 + * 375 + * Return configuration for provided VME slave window. 376 + * 377 + * Return: Zero on success, -EINVAL if operation is not supported on this 378 + * device or if an invalid resource has been provided. 379 + */ 412 380 int vme_slave_get(struct vme_resource *resource, int *enabled, 413 381 unsigned long long *vme_base, unsigned long long *size, 414 382 dma_addr_t *buf_base, u32 *aspace, u32 *cycle) ··· 448 386 } 449 387 EXPORT_SYMBOL(vme_slave_get); 450 388 389 + /** 390 + * vme_slave_free - Free VME slave window 391 + * @resource: Pointer to VME slave resource. 392 + * 393 + * Free the provided slave resource so that it may be reallocated. 394 + */ 451 395 void vme_slave_free(struct vme_resource *resource) 452 396 { 453 397 struct vme_slave_resource *slave_image; ··· 483 415 } 484 416 EXPORT_SYMBOL(vme_slave_free); 485 417 486 - /* 487 - * Request a master image with specific attributes, return some unique 488 - * identifier. 418 + /** 419 + * vme_master_request - Request a VME master window resource. 420 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 421 + * @address: Required VME address space. 422 + * @cycle: Required VME data transfer cycle type. 423 + * @dwidth: Required VME data transfer width. 424 + * 425 + * Request use of a VME window resource capable of being set for the requested 426 + * address space, data transfer cycle and width. 427 + * 428 + * Return: Pointer to VME resource on success, NULL on failure. 489 429 */ 490 430 struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address, 491 431 u32 cycle, u32 dwidth) ··· 562 486 } 563 487 EXPORT_SYMBOL(vme_master_request); 564 488 489 + /** 490 + * vme_master_set - Set VME master window configuration. 491 + * @resource: Pointer to VME master resource. 492 + * @enabled: State to which the window should be configured. 493 + * @vme_base: Base address for the window. 494 + * @size: Size of the VME window. 495 + * @aspace: VME address space for the VME window. 496 + * @cycle: VME data transfer cycle type for the VME window. 497 + * @dwidth: VME data transfer width for the VME window. 498 + * 499 + * Set configuration for provided VME master window. 500 + * 501 + * Return: Zero on success, -EINVAL if operation is not supported on this 502 + * device, if an invalid resource has been provided or invalid 503 + * attributes are provided. Hardware specific errors may also be 504 + * returned. 505 + */ 565 506 int vme_master_set(struct vme_resource *resource, int enabled, 566 507 unsigned long long vme_base, unsigned long long size, u32 aspace, 567 508 u32 cycle, u32 dwidth) ··· 615 522 } 616 523 EXPORT_SYMBOL(vme_master_set); 617 524 525 + /** 526 + * vme_master_get - Retrieve VME master window configuration. 527 + * @resource: Pointer to VME master resource. 528 + * @enabled: Pointer to variable for storing state. 529 + * @vme_base: Pointer to variable for storing window base address. 530 + * @size: Pointer to variable for storing window size. 531 + * @aspace: Pointer to variable for storing VME address space. 532 + * @cycle: Pointer to variable for storing VME data transfer cycle type. 533 + * @dwidth: Pointer to variable for storing VME data transfer width. 534 + * 535 + * Return configuration for provided VME master window. 536 + * 537 + * Return: Zero on success, -EINVAL if operation is not supported on this 538 + * device or if an invalid resource has been provided. 539 + */ 618 540 int vme_master_get(struct vme_resource *resource, int *enabled, 619 541 unsigned long long *vme_base, unsigned long long *size, u32 *aspace, 620 542 u32 *cycle, u32 *dwidth) ··· 654 546 } 655 547 EXPORT_SYMBOL(vme_master_get); 656 548 657 - /* 658 - * Read data out of VME space into a buffer. 549 + /** 550 + * vme_master_write - Read data from VME space into a buffer. 551 + * @resource: Pointer to VME master resource. 552 + * @buf: Pointer to buffer where data should be transferred. 553 + * @count: Number of bytes to transfer. 554 + * @offset: Offset into VME master window at which to start transfer. 555 + * 556 + * Perform read of count bytes of data from location on VME bus which maps into 557 + * the VME master window at offset to buf. 558 + * 559 + * Return: Number of bytes read, -EINVAL if resource is not a VME master 560 + * resource or read operation is not supported. -EFAULT returned if 561 + * invalid offset is provided. Hardware specific errors may also be 562 + * returned. 659 563 */ 660 564 ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count, 661 565 loff_t offset) ··· 703 583 } 704 584 EXPORT_SYMBOL(vme_master_read); 705 585 706 - /* 707 - * Write data out to VME space from a buffer. 586 + /** 587 + * vme_master_write - Write data out to VME space from a buffer. 588 + * @resource: Pointer to VME master resource. 589 + * @buf: Pointer to buffer holding data to transfer. 590 + * @count: Number of bytes to transfer. 591 + * @offset: Offset into VME master window at which to start transfer. 592 + * 593 + * Perform write of count bytes of data from buf to location on VME bus which 594 + * maps into the VME master window at offset. 595 + * 596 + * Return: Number of bytes written, -EINVAL if resource is not a VME master 597 + * resource or write operation is not supported. -EFAULT returned if 598 + * invalid offset is provided. Hardware specific errors may also be 599 + * returned. 708 600 */ 709 601 ssize_t vme_master_write(struct vme_resource *resource, void *buf, 710 602 size_t count, loff_t offset) ··· 751 619 } 752 620 EXPORT_SYMBOL(vme_master_write); 753 621 754 - /* 755 - * Perform RMW cycle to provided location. 622 + /** 623 + * vme_master_rmw - Perform read-modify-write cycle. 624 + * @resource: Pointer to VME master resource. 625 + * @mask: Bits to be compared and swapped in operation. 626 + * @compare: Bits to be compared with data read from offset. 627 + * @swap: Bits to be swapped in data read from offset. 628 + * @offset: Offset into VME master window at which to perform operation. 629 + * 630 + * Perform read-modify-write cycle on provided location: 631 + * - Location on VME bus is read. 632 + * - Bits selected by mask are compared with compare. 633 + * - Where a selected bit matches that in compare and are selected in swap, 634 + * the bit is swapped. 635 + * - Result written back to location on VME bus. 636 + * 637 + * Return: Bytes written on success, -EINVAL if resource is not a VME master 638 + * resource or RMW operation is not supported. Hardware specific 639 + * errors may also be returned. 756 640 */ 757 641 unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask, 758 642 unsigned int compare, unsigned int swap, loff_t offset) ··· 792 644 } 793 645 EXPORT_SYMBOL(vme_master_rmw); 794 646 647 + /** 648 + * vme_master_mmap - Mmap region of VME master window. 649 + * @resource: Pointer to VME master resource. 650 + * @vma: Pointer to definition of user mapping. 651 + * 652 + * Memory map a region of the VME master window into user space. 653 + * 654 + * Return: Zero on success, -EINVAL if resource is not a VME master 655 + * resource or -EFAULT if map exceeds window size. Other generic mmap 656 + * errors may also be returned. 657 + */ 795 658 int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma) 796 659 { 797 660 struct vme_master_resource *image; ··· 829 670 } 830 671 EXPORT_SYMBOL(vme_master_mmap); 831 672 673 + /** 674 + * vme_master_free - Free VME master window 675 + * @resource: Pointer to VME master resource. 676 + * 677 + * Free the provided master resource so that it may be reallocated. 678 + */ 832 679 void vme_master_free(struct vme_resource *resource) 833 680 { 834 681 struct vme_master_resource *master_image; ··· 864 699 } 865 700 EXPORT_SYMBOL(vme_master_free); 866 701 867 - /* 868 - * Request a DMA controller with specific attributes, return some unique 869 - * identifier. 702 + /** 703 + * vme_dma_request - Request a DMA controller. 704 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 705 + * @route: Required src/destination combination. 706 + * 707 + * Request a VME DMA controller with capability to perform transfers bewteen 708 + * requested source/destination combination. 709 + * 710 + * Return: Pointer to VME DMA resource on success, NULL on failure. 870 711 */ 871 712 struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route) 872 713 { ··· 939 768 } 940 769 EXPORT_SYMBOL(vme_dma_request); 941 770 942 - /* 943 - * Start new list 771 + /** 772 + * vme_new_dma_list - Create new VME DMA list. 773 + * @resource: Pointer to VME DMA resource. 774 + * 775 + * Create a new VME DMA list. It is the responsibility of the user to free 776 + * the list once it is no longer required with vme_dma_list_free(). 777 + * 778 + * Return: Pointer to new VME DMA list, NULL on allocation failure or invalid 779 + * VME DMA resource. 944 780 */ 945 781 struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource) 946 782 { ··· 974 796 } 975 797 EXPORT_SYMBOL(vme_new_dma_list); 976 798 977 - /* 978 - * Create "Pattern" type attributes 799 + /** 800 + * vme_dma_pattern_attribute - Create "Pattern" type VME DMA list attribute. 801 + * @pattern: Value to use used as pattern 802 + * @type: Type of pattern to be written. 803 + * 804 + * Create VME DMA list attribute for pattern generation. It is the 805 + * responsibility of the user to free used attributes using 806 + * vme_dma_free_attribute(). 807 + * 808 + * Return: Pointer to VME DMA attribute, NULL on failure. 979 809 */ 980 810 struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type) 981 811 { ··· 1017 831 } 1018 832 EXPORT_SYMBOL(vme_dma_pattern_attribute); 1019 833 1020 - /* 1021 - * Create "PCI" type attributes 834 + /** 835 + * vme_dma_pci_attribute - Create "PCI" type VME DMA list attribute. 836 + * @address: PCI base address for DMA transfer. 837 + * 838 + * Create VME DMA list attribute pointing to a location on PCI for DMA 839 + * transfers. It is the responsibility of the user to free used attributes 840 + * using vme_dma_free_attribute(). 841 + * 842 + * Return: Pointer to VME DMA attribute, NULL on failure. 1022 843 */ 1023 844 struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address) 1024 845 { ··· 1062 869 } 1063 870 EXPORT_SYMBOL(vme_dma_pci_attribute); 1064 871 1065 - /* 1066 - * Create "VME" type attributes 872 + /** 873 + * vme_dma_vme_attribute - Create "VME" type VME DMA list attribute. 874 + * @address: VME base address for DMA transfer. 875 + * @aspace: VME address space to use for DMA transfer. 876 + * @cycle: VME bus cycle to use for DMA transfer. 877 + * @dwidth: VME data width to use for DMA transfer. 878 + * 879 + * Create VME DMA list attribute pointing to a location on the VME bus for DMA 880 + * transfers. It is the responsibility of the user to free used attributes 881 + * using vme_dma_free_attribute(). 882 + * 883 + * Return: Pointer to VME DMA attribute, NULL on failure. 1067 884 */ 1068 885 struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address, 1069 886 u32 aspace, u32 cycle, u32 dwidth) ··· 1111 908 } 1112 909 EXPORT_SYMBOL(vme_dma_vme_attribute); 1113 910 1114 - /* 1115 - * Free attribute 911 + /** 912 + * vme_dma_free_attribute - Free DMA list attribute. 913 + * @attributes: Pointer to DMA list attribute. 914 + * 915 + * Free VME DMA list attribute. VME DMA list attributes can be safely freed 916 + * once vme_dma_list_add() has returned. 1116 917 */ 1117 918 void vme_dma_free_attribute(struct vme_dma_attr *attributes) 1118 919 { ··· 1125 918 } 1126 919 EXPORT_SYMBOL(vme_dma_free_attribute); 1127 920 921 + /** 922 + * vme_dma_list_add - Add enty to a VME DMA list. 923 + * @list: Pointer to VME list. 924 + * @src: Pointer to DMA list attribute to use as source. 925 + * @dest: Pointer to DMA list attribute to use as destination. 926 + * @count: Number of bytes to transfer. 927 + * 928 + * Add an entry to the provided VME DMA list. Entry requires pointers to source 929 + * and destination DMA attributes and a count. 930 + * 931 + * Please note, the attributes supported as source and destinations for 932 + * transfers are hardware dependent. 933 + * 934 + * Return: Zero on success, -EINVAL if operation is not supported on this 935 + * device or if the link list has already been submitted for execution. 936 + * Hardware specific errors also possible. 937 + */ 1128 938 int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, 1129 939 struct vme_dma_attr *dest, size_t count) 1130 940 { ··· 1166 942 } 1167 943 EXPORT_SYMBOL(vme_dma_list_add); 1168 944 945 + /** 946 + * vme_dma_list_exec - Queue a VME DMA list for execution. 947 + * @list: Pointer to VME list. 948 + * 949 + * Queue the provided VME DMA list for execution. The call will return once the 950 + * list has been executed. 951 + * 952 + * Return: Zero on success, -EINVAL if operation is not supported on this 953 + * device. Hardware specific errors also possible. 954 + */ 1169 955 int vme_dma_list_exec(struct vme_dma_list *list) 1170 956 { 1171 957 struct vme_bridge *bridge = list->parent->parent; ··· 1196 962 } 1197 963 EXPORT_SYMBOL(vme_dma_list_exec); 1198 964 965 + /** 966 + * vme_dma_list_free - Free a VME DMA list. 967 + * @list: Pointer to VME list. 968 + * 969 + * Free the provided DMA list and all its entries. 970 + * 971 + * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource 972 + * is still in use. Hardware specific errors also possible. 973 + */ 1199 974 int vme_dma_list_free(struct vme_dma_list *list) 1200 975 { 1201 976 struct vme_bridge *bridge = list->parent->parent; ··· 1237 994 } 1238 995 EXPORT_SYMBOL(vme_dma_list_free); 1239 996 997 + /** 998 + * vme_dma_free - Free a VME DMA resource. 999 + * @resource: Pointer to VME DMA resource. 1000 + * 1001 + * Free the provided DMA resource so that it may be reallocated. 1002 + * 1003 + * Return: Zero on success, -EINVAL on invalid VME resource, -EBUSY if resource 1004 + * is still active. 1005 + */ 1240 1006 int vme_dma_free(struct vme_resource *resource) 1241 1007 { 1242 1008 struct vme_dma_resource *ctrlr; ··· 1351 1099 } 1352 1100 EXPORT_SYMBOL(vme_irq_handler); 1353 1101 1102 + /** 1103 + * vme_irq_request - Request a specific VME interrupt. 1104 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1105 + * @level: Interrupt priority being requested. 1106 + * @statid: Interrupt vector being requested. 1107 + * @callback: Pointer to callback function called when VME interrupt/vector 1108 + * received. 1109 + * @priv_data: Generic pointer that will be passed to the callback function. 1110 + * 1111 + * Request callback to be attached as a handler for VME interrupts with provided 1112 + * level and statid. 1113 + * 1114 + * Return: Zero on success, -EINVAL on invalid vme device, level or if the 1115 + * function is not supported, -EBUSY if the level/statid combination is 1116 + * already in use. Hardware specific errors also possible. 1117 + */ 1354 1118 int vme_irq_request(struct vme_dev *vdev, int level, int statid, 1355 1119 void (*callback)(int, int, void *), 1356 1120 void *priv_data) ··· 1410 1142 } 1411 1143 EXPORT_SYMBOL(vme_irq_request); 1412 1144 1145 + /** 1146 + * vme_irq_free - Free a VME interrupt. 1147 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1148 + * @level: Interrupt priority of interrupt being freed. 1149 + * @statid: Interrupt vector of interrupt being freed. 1150 + * 1151 + * Remove previously attached callback from VME interrupt priority/vector. 1152 + */ 1413 1153 void vme_irq_free(struct vme_dev *vdev, int level, int statid) 1414 1154 { 1415 1155 struct vme_bridge *bridge; ··· 1453 1177 } 1454 1178 EXPORT_SYMBOL(vme_irq_free); 1455 1179 1180 + /** 1181 + * vme_irq_generate - Generate VME interrupt. 1182 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1183 + * @level: Interrupt priority at which to assert the interrupt. 1184 + * @statid: Interrupt vector to associate with the interrupt. 1185 + * 1186 + * Generate a VME interrupt of the provided level and with the provided 1187 + * statid. 1188 + * 1189 + * Return: Zero on success, -EINVAL on invalid vme device, level or if the 1190 + * function is not supported. Hardware specific errors also possible. 1191 + */ 1456 1192 int vme_irq_generate(struct vme_dev *vdev, int level, int statid) 1457 1193 { 1458 1194 struct vme_bridge *bridge; ··· 1489 1201 } 1490 1202 EXPORT_SYMBOL(vme_irq_generate); 1491 1203 1492 - /* 1493 - * Request the location monitor, return resource or NULL 1204 + /** 1205 + * vme_lm_request - Request a VME location monitor 1206 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1207 + * 1208 + * Allocate a location monitor resource to the driver. A location monitor 1209 + * allows the driver to monitor accesses to a contiguous number of 1210 + * addresses on the VME bus. 1211 + * 1212 + * Return: Pointer to a VME resource on success or NULL on failure. 1494 1213 */ 1495 1214 struct vme_resource *vme_lm_request(struct vme_dev *vdev) 1496 1215 { ··· 1513 1218 goto err_bus; 1514 1219 } 1515 1220 1516 - /* Loop through DMA resources */ 1221 + /* Loop through LM resources */ 1517 1222 list_for_each(lm_pos, &bridge->lm_resources) { 1518 1223 lm = list_entry(lm_pos, 1519 1224 struct vme_lm_resource, list); ··· 1559 1264 } 1560 1265 EXPORT_SYMBOL(vme_lm_request); 1561 1266 1267 + /** 1268 + * vme_lm_count - Determine number of VME Addresses monitored 1269 + * @resource: Pointer to VME location monitor resource. 1270 + * 1271 + * The number of contiguous addresses monitored is hardware dependent. 1272 + * Return the number of contiguous addresses monitored by the 1273 + * location monitor. 1274 + * 1275 + * Return: Count of addresses monitored or -EINVAL when provided with an 1276 + * invalid location monitor resource. 1277 + */ 1562 1278 int vme_lm_count(struct vme_resource *resource) 1563 1279 { 1564 1280 struct vme_lm_resource *lm; ··· 1585 1279 } 1586 1280 EXPORT_SYMBOL(vme_lm_count); 1587 1281 1282 + /** 1283 + * vme_lm_set - Configure location monitor 1284 + * @resource: Pointer to VME location monitor resource. 1285 + * @lm_base: Base address to monitor. 1286 + * @aspace: VME address space to monitor. 1287 + * @cycle: VME bus cycle type to monitor. 1288 + * 1289 + * Set the base address, address space and cycle type of accesses to be 1290 + * monitored by the location monitor. 1291 + * 1292 + * Return: Zero on success, -EINVAL when provided with an invalid location 1293 + * monitor resource or function is not supported. Hardware specific 1294 + * errors may also be returned. 1295 + */ 1588 1296 int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base, 1589 1297 u32 aspace, u32 cycle) 1590 1298 { ··· 1621 1301 } 1622 1302 EXPORT_SYMBOL(vme_lm_set); 1623 1303 1304 + /** 1305 + * vme_lm_get - Retrieve location monitor settings 1306 + * @resource: Pointer to VME location monitor resource. 1307 + * @lm_base: Pointer used to output the base address monitored. 1308 + * @aspace: Pointer used to output the address space monitored. 1309 + * @cycle: Pointer used to output the VME bus cycle type monitored. 1310 + * 1311 + * Retrieve the base address, address space and cycle type of accesses to 1312 + * be monitored by the location monitor. 1313 + * 1314 + * Return: Zero on success, -EINVAL when provided with an invalid location 1315 + * monitor resource or function is not supported. Hardware specific 1316 + * errors may also be returned. 1317 + */ 1624 1318 int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base, 1625 1319 u32 *aspace, u32 *cycle) 1626 1320 { ··· 1657 1323 } 1658 1324 EXPORT_SYMBOL(vme_lm_get); 1659 1325 1326 + /** 1327 + * vme_lm_attach - Provide callback for location monitor address 1328 + * @resource: Pointer to VME location monitor resource. 1329 + * @monitor: Offset to which callback should be attached. 1330 + * @callback: Pointer to callback function called when triggered. 1331 + * @data: Generic pointer that will be passed to the callback function. 1332 + * 1333 + * Attach a callback to the specificed offset into the location monitors 1334 + * monitored addresses. A generic pointer is provided to allow data to be 1335 + * passed to the callback when called. 1336 + * 1337 + * Return: Zero on success, -EINVAL when provided with an invalid location 1338 + * monitor resource or function is not supported. Hardware specific 1339 + * errors may also be returned. 1340 + */ 1660 1341 int vme_lm_attach(struct vme_resource *resource, int monitor, 1661 1342 void (*callback)(void *), void *data) 1662 1343 { ··· 1694 1345 } 1695 1346 EXPORT_SYMBOL(vme_lm_attach); 1696 1347 1348 + /** 1349 + * vme_lm_detach - Remove callback for location monitor address 1350 + * @resource: Pointer to VME location monitor resource. 1351 + * @monitor: Offset to which callback should be removed. 1352 + * 1353 + * Remove the callback associated with the specificed offset into the 1354 + * location monitors monitored addresses. 1355 + * 1356 + * Return: Zero on success, -EINVAL when provided with an invalid location 1357 + * monitor resource or function is not supported. Hardware specific 1358 + * errors may also be returned. 1359 + */ 1697 1360 int vme_lm_detach(struct vme_resource *resource, int monitor) 1698 1361 { 1699 1362 struct vme_bridge *bridge = find_bridge(resource); ··· 1727 1366 } 1728 1367 EXPORT_SYMBOL(vme_lm_detach); 1729 1368 1369 + /** 1370 + * vme_lm_free - Free allocated VME location monitor 1371 + * @resource: Pointer to VME location monitor resource. 1372 + * 1373 + * Free allocation of a VME location monitor. 1374 + * 1375 + * WARNING: This function currently expects that any callbacks that have 1376 + * been attached to the location monitor have been removed. 1377 + * 1378 + * Return: Zero on success, -EINVAL when provided with an invalid location 1379 + * monitor resource. 1380 + */ 1730 1381 void vme_lm_free(struct vme_resource *resource) 1731 1382 { 1732 1383 struct vme_lm_resource *lm; ··· 1765 1392 } 1766 1393 EXPORT_SYMBOL(vme_lm_free); 1767 1394 1395 + /** 1396 + * vme_slot_num - Retrieve slot ID 1397 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1398 + * 1399 + * Retrieve the slot ID associated with the provided VME device. 1400 + * 1401 + * Return: The slot ID on success, -EINVAL if VME bridge cannot be determined 1402 + * or the function is not supported. Hardware specific errors may also 1403 + * be returned. 1404 + */ 1768 1405 int vme_slot_num(struct vme_dev *vdev) 1769 1406 { 1770 1407 struct vme_bridge *bridge; ··· 1794 1411 } 1795 1412 EXPORT_SYMBOL(vme_slot_num); 1796 1413 1414 + /** 1415 + * vme_bus_num - Retrieve bus number 1416 + * @vdev: Pointer to VME device struct vme_dev assigned to driver instance. 1417 + * 1418 + * Retrieve the bus enumeration associated with the provided VME device. 1419 + * 1420 + * Return: The bus number on success, -EINVAL if VME bridge cannot be 1421 + * determined. 1422 + */ 1797 1423 int vme_bus_num(struct vme_dev *vdev) 1798 1424 { 1799 1425 struct vme_bridge *bridge; ··· 1948 1556 return err; 1949 1557 } 1950 1558 1559 + /** 1560 + * vme_register_driver - Register a VME driver 1561 + * @drv: Pointer to VME driver structure to register. 1562 + * @ndevs: Maximum number of devices to allow to be enumerated. 1563 + * 1564 + * Register a VME device driver with the VME subsystem. 1565 + * 1566 + * Return: Zero on success, error value on registration failure. 1567 + */ 1951 1568 int vme_register_driver(struct vme_driver *drv, unsigned int ndevs) 1952 1569 { 1953 1570 int err; ··· 1977 1576 } 1978 1577 EXPORT_SYMBOL(vme_register_driver); 1979 1578 1579 + /** 1580 + * vme_unregister_driver - Unregister a VME driver 1581 + * @drv: Pointer to VME driver structure to unregister. 1582 + * 1583 + * Unregister a VME device driver from the VME subsystem. 1584 + */ 1980 1585 void vme_unregister_driver(struct vme_driver *drv) 1981 1586 { 1982 1587 struct vme_dev *dev, *dev_tmp;
-6
drivers/w1/masters/matrox_w1.c
··· 36 36 37 37 #include "../w1.h" 38 38 #include "../w1_int.h" 39 - #include "../w1_log.h" 40 39 41 40 MODULE_LICENSE("GPL"); 42 41 MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>"); ··· 156 157 struct matrox_device *dev; 157 158 int err; 158 159 159 - assert(pdev != NULL); 160 - assert(ent != NULL); 161 - 162 160 if (pdev->vendor != PCI_VENDOR_ID_MATROX || pdev->device != PCI_DEVICE_ID_MATROX_G400) 163 161 return -ENODEV; 164 162 ··· 219 223 static void matrox_w1_remove(struct pci_dev *pdev) 220 224 { 221 225 struct matrox_device *dev = pci_get_drvdata(pdev); 222 - 223 - assert(dev != NULL); 224 226 225 227 if (dev->found) { 226 228 w1_remove_master_device(dev->bus_master);
+6
drivers/w1/slaves/Kconfig
··· 86 86 Each block has 30 bytes of data and a two byte CRC16. 87 87 Full block writes are only allowed if the CRC is valid. 88 88 89 + config W1_SLAVE_DS2438 90 + tristate "DS2438 Smart Battery Monitor 0x26 family support" 91 + help 92 + Say Y here if you want to use a 1-wire 93 + DS2438 Smart Battery Monitor device support 94 + 89 95 config W1_SLAVE_DS2760 90 96 tristate "Dallas 2760 battery monitor chip (HP iPAQ & others)" 91 97 help
+1
drivers/w1/slaves/Makefile
··· 11 11 obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o 12 12 obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o 13 13 obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o 14 + obj-$(CONFIG_W1_SLAVE_DS2438) += w1_ds2438.o 14 15 obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o 15 16 obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o 16 17 obj-$(CONFIG_W1_SLAVE_DS2781) += w1_ds2781.o
+390
drivers/w1/slaves/w1_ds2438.c
··· 1 + /* 2 + * 1-Wire implementation for the ds2438 chip 3 + * 4 + * Copyright (c) 2017 Mariusz Bialonczyk <manio@skyboo.net> 5 + * 6 + * This source code is licensed under the GNU General Public License, 7 + * Version 2. See the file COPYING for more details. 8 + */ 9 + 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/device.h> 13 + #include <linux/types.h> 14 + #include <linux/delay.h> 15 + 16 + #include "../w1.h" 17 + #include "../w1_family.h" 18 + 19 + #define W1_DS2438_RETRIES 3 20 + 21 + /* Memory commands */ 22 + #define W1_DS2438_READ_SCRATCH 0xBE 23 + #define W1_DS2438_WRITE_SCRATCH 0x4E 24 + #define W1_DS2438_COPY_SCRATCH 0x48 25 + #define W1_DS2438_RECALL_MEMORY 0xB8 26 + /* Register commands */ 27 + #define W1_DS2438_CONVERT_TEMP 0x44 28 + #define W1_DS2438_CONVERT_VOLTAGE 0xB4 29 + 30 + #define DS2438_PAGE_SIZE 8 31 + #define DS2438_ADC_INPUT_VAD 0 32 + #define DS2438_ADC_INPUT_VDD 1 33 + #define DS2438_MAX_CONVERSION_TIME 10 /* ms */ 34 + 35 + /* Page #0 definitions */ 36 + #define DS2438_STATUS_REG 0x00 /* Status/Configuration Register */ 37 + #define DS2438_STATUS_IAD (1 << 0) /* Current A/D Control Bit */ 38 + #define DS2438_STATUS_CA (1 << 1) /* Current Accumulator Configuration */ 39 + #define DS2438_STATUS_EE (1 << 2) /* Current Accumulator Shadow Selector bit */ 40 + #define DS2438_STATUS_AD (1 << 3) /* Voltage A/D Input Select Bit */ 41 + #define DS2438_STATUS_TB (1 << 4) /* Temperature Busy Flag */ 42 + #define DS2438_STATUS_NVB (1 << 5) /* Nonvolatile Memory Busy Flag */ 43 + #define DS2438_STATUS_ADB (1 << 6) /* A/D Converter Busy Flag */ 44 + 45 + #define DS2438_TEMP_LSB 0x01 46 + #define DS2438_TEMP_MSB 0x02 47 + #define DS2438_VOLTAGE_LSB 0x03 48 + #define DS2438_VOLTAGE_MSB 0x04 49 + #define DS2438_CURRENT_LSB 0x05 50 + #define DS2438_CURRENT_MSB 0x06 51 + #define DS2438_THRESHOLD 0x07 52 + 53 + int w1_ds2438_get_page(struct w1_slave *sl, int pageno, u8 *buf) 54 + { 55 + unsigned int retries = W1_DS2438_RETRIES; 56 + u8 w1_buf[2]; 57 + u8 crc; 58 + size_t count; 59 + 60 + while (retries--) { 61 + crc = 0; 62 + 63 + if (w1_reset_select_slave(sl)) 64 + continue; 65 + w1_buf[0] = W1_DS2438_RECALL_MEMORY; 66 + w1_buf[1] = 0x00; 67 + w1_write_block(sl->master, w1_buf, 2); 68 + 69 + if (w1_reset_select_slave(sl)) 70 + continue; 71 + w1_buf[0] = W1_DS2438_READ_SCRATCH; 72 + w1_buf[1] = 0x00; 73 + w1_write_block(sl->master, w1_buf, 2); 74 + 75 + count = w1_read_block(sl->master, buf, DS2438_PAGE_SIZE + 1); 76 + if (count == DS2438_PAGE_SIZE + 1) { 77 + crc = w1_calc_crc8(buf, DS2438_PAGE_SIZE); 78 + 79 + /* check for correct CRC */ 80 + if ((u8)buf[DS2438_PAGE_SIZE] == crc) 81 + return 0; 82 + } 83 + } 84 + return -1; 85 + } 86 + 87 + int w1_ds2438_get_temperature(struct w1_slave *sl, int16_t *temperature) 88 + { 89 + unsigned int retries = W1_DS2438_RETRIES; 90 + u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/]; 91 + unsigned int tm = DS2438_MAX_CONVERSION_TIME; 92 + unsigned long sleep_rem; 93 + int ret; 94 + 95 + mutex_lock(&sl->master->bus_mutex); 96 + 97 + while (retries--) { 98 + if (w1_reset_select_slave(sl)) 99 + continue; 100 + w1_write_8(sl->master, W1_DS2438_CONVERT_TEMP); 101 + 102 + mutex_unlock(&sl->master->bus_mutex); 103 + sleep_rem = msleep_interruptible(tm); 104 + if (sleep_rem != 0) { 105 + ret = -1; 106 + goto post_unlock; 107 + } 108 + 109 + if (mutex_lock_interruptible(&sl->master->bus_mutex) != 0) { 110 + ret = -1; 111 + goto post_unlock; 112 + } 113 + 114 + break; 115 + } 116 + 117 + if (w1_ds2438_get_page(sl, 0, w1_buf) == 0) { 118 + *temperature = (((int16_t) w1_buf[DS2438_TEMP_MSB]) << 8) | ((uint16_t) w1_buf[DS2438_TEMP_LSB]); 119 + ret = 0; 120 + } else 121 + ret = -1; 122 + 123 + mutex_unlock(&sl->master->bus_mutex); 124 + 125 + post_unlock: 126 + return ret; 127 + } 128 + 129 + int w1_ds2438_change_config_bit(struct w1_slave *sl, u8 mask, u8 value) 130 + { 131 + unsigned int retries = W1_DS2438_RETRIES; 132 + u8 w1_buf[3]; 133 + u8 status; 134 + int perform_write = 0; 135 + 136 + while (retries--) { 137 + if (w1_reset_select_slave(sl)) 138 + continue; 139 + w1_buf[0] = W1_DS2438_RECALL_MEMORY; 140 + w1_buf[1] = 0x00; 141 + w1_write_block(sl->master, w1_buf, 2); 142 + 143 + if (w1_reset_select_slave(sl)) 144 + continue; 145 + w1_buf[0] = W1_DS2438_READ_SCRATCH; 146 + w1_buf[1] = 0x00; 147 + w1_write_block(sl->master, w1_buf, 2); 148 + 149 + /* reading one byte of result */ 150 + status = w1_read_8(sl->master); 151 + 152 + /* if bit0=1, set a value to a mask for easy compare */ 153 + if (value) 154 + value = mask; 155 + 156 + if ((status & mask) == value) 157 + return 0; /* already set as requested */ 158 + else { 159 + /* changing bit */ 160 + status ^= mask; 161 + perform_write = 1; 162 + } 163 + break; 164 + } 165 + 166 + if (perform_write) { 167 + retries = W1_DS2438_RETRIES; 168 + while (retries--) { 169 + if (w1_reset_select_slave(sl)) 170 + continue; 171 + w1_buf[0] = W1_DS2438_WRITE_SCRATCH; 172 + w1_buf[1] = 0x00; 173 + w1_buf[2] = status; 174 + w1_write_block(sl->master, w1_buf, 3); 175 + 176 + if (w1_reset_select_slave(sl)) 177 + continue; 178 + w1_buf[0] = W1_DS2438_COPY_SCRATCH; 179 + w1_buf[1] = 0x00; 180 + w1_write_block(sl->master, w1_buf, 2); 181 + 182 + return 0; 183 + } 184 + } 185 + return -1; 186 + } 187 + 188 + uint16_t w1_ds2438_get_voltage(struct w1_slave *sl, int adc_input, uint16_t *voltage) 189 + { 190 + unsigned int retries = W1_DS2438_RETRIES; 191 + u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/]; 192 + unsigned int tm = DS2438_MAX_CONVERSION_TIME; 193 + unsigned long sleep_rem; 194 + int ret; 195 + 196 + mutex_lock(&sl->master->bus_mutex); 197 + 198 + if (w1_ds2438_change_config_bit(sl, DS2438_STATUS_AD, adc_input)) { 199 + ret = -1; 200 + goto pre_unlock; 201 + } 202 + 203 + while (retries--) { 204 + if (w1_reset_select_slave(sl)) 205 + continue; 206 + w1_write_8(sl->master, W1_DS2438_CONVERT_VOLTAGE); 207 + 208 + mutex_unlock(&sl->master->bus_mutex); 209 + sleep_rem = msleep_interruptible(tm); 210 + if (sleep_rem != 0) { 211 + ret = -1; 212 + goto post_unlock; 213 + } 214 + 215 + if (mutex_lock_interruptible(&sl->master->bus_mutex) != 0) { 216 + ret = -1; 217 + goto post_unlock; 218 + } 219 + 220 + break; 221 + } 222 + 223 + if (w1_ds2438_get_page(sl, 0, w1_buf) == 0) { 224 + *voltage = (((uint16_t) w1_buf[DS2438_VOLTAGE_MSB]) << 8) | ((uint16_t) w1_buf[DS2438_VOLTAGE_LSB]); 225 + ret = 0; 226 + } else 227 + ret = -1; 228 + 229 + pre_unlock: 230 + mutex_unlock(&sl->master->bus_mutex); 231 + 232 + post_unlock: 233 + return ret; 234 + } 235 + 236 + static ssize_t iad_write(struct file *filp, struct kobject *kobj, 237 + struct bin_attribute *bin_attr, char *buf, 238 + loff_t off, size_t count) 239 + { 240 + struct w1_slave *sl = kobj_to_w1_slave(kobj); 241 + int ret; 242 + 243 + if (count != 1 || off != 0) 244 + return -EFAULT; 245 + 246 + mutex_lock(&sl->master->bus_mutex); 247 + 248 + if (w1_ds2438_change_config_bit(sl, DS2438_STATUS_IAD, *buf & 0x01) == 0) 249 + ret = 1; 250 + else 251 + ret = -EIO; 252 + 253 + mutex_unlock(&sl->master->bus_mutex); 254 + 255 + return ret; 256 + } 257 + 258 + static ssize_t page0_read(struct file *filp, struct kobject *kobj, 259 + struct bin_attribute *bin_attr, char *buf, 260 + loff_t off, size_t count) 261 + { 262 + struct w1_slave *sl = kobj_to_w1_slave(kobj); 263 + int ret; 264 + u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/]; 265 + 266 + if (off != 0) 267 + return 0; 268 + if (!buf) 269 + return -EINVAL; 270 + 271 + mutex_lock(&sl->master->bus_mutex); 272 + 273 + if (w1_ds2438_get_page(sl, 0, w1_buf) == 0) { 274 + memcpy(buf, &w1_buf, DS2438_PAGE_SIZE); 275 + ret = DS2438_PAGE_SIZE; 276 + } else 277 + ret = -EIO; 278 + 279 + mutex_unlock(&sl->master->bus_mutex); 280 + 281 + return ret; 282 + } 283 + 284 + static ssize_t temperature_read(struct file *filp, struct kobject *kobj, 285 + struct bin_attribute *bin_attr, char *buf, 286 + loff_t off, size_t count) 287 + { 288 + struct w1_slave *sl = kobj_to_w1_slave(kobj); 289 + int ret; 290 + ssize_t c = PAGE_SIZE; 291 + int16_t temp; 292 + 293 + if (off != 0) 294 + return 0; 295 + if (!buf) 296 + return -EINVAL; 297 + 298 + if (w1_ds2438_get_temperature(sl, &temp) == 0) { 299 + c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", temp); 300 + ret = PAGE_SIZE - c; 301 + } else 302 + ret = -EIO; 303 + 304 + return ret; 305 + } 306 + 307 + static ssize_t vad_read(struct file *filp, struct kobject *kobj, 308 + struct bin_attribute *bin_attr, char *buf, 309 + loff_t off, size_t count) 310 + { 311 + struct w1_slave *sl = kobj_to_w1_slave(kobj); 312 + int ret; 313 + ssize_t c = PAGE_SIZE; 314 + uint16_t voltage; 315 + 316 + if (off != 0) 317 + return 0; 318 + if (!buf) 319 + return -EINVAL; 320 + 321 + if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage) == 0) { 322 + c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", voltage); 323 + ret = PAGE_SIZE - c; 324 + } else 325 + ret = -EIO; 326 + 327 + return ret; 328 + } 329 + 330 + static ssize_t vdd_read(struct file *filp, struct kobject *kobj, 331 + struct bin_attribute *bin_attr, char *buf, 332 + loff_t off, size_t count) 333 + { 334 + struct w1_slave *sl = kobj_to_w1_slave(kobj); 335 + int ret; 336 + ssize_t c = PAGE_SIZE; 337 + uint16_t voltage; 338 + 339 + if (off != 0) 340 + return 0; 341 + if (!buf) 342 + return -EINVAL; 343 + 344 + if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage) == 0) { 345 + c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", voltage); 346 + ret = PAGE_SIZE - c; 347 + } else 348 + ret = -EIO; 349 + 350 + return ret; 351 + } 352 + 353 + static BIN_ATTR(iad, S_IRUGO | S_IWUSR | S_IWGRP, NULL, iad_write, 1); 354 + static BIN_ATTR_RO(page0, DS2438_PAGE_SIZE); 355 + static BIN_ATTR_RO(temperature, 0/* real length varies */); 356 + static BIN_ATTR_RO(vad, 0/* real length varies */); 357 + static BIN_ATTR_RO(vdd, 0/* real length varies */); 358 + 359 + static struct bin_attribute *w1_ds2438_bin_attrs[] = { 360 + &bin_attr_iad, 361 + &bin_attr_page0, 362 + &bin_attr_temperature, 363 + &bin_attr_vad, 364 + &bin_attr_vdd, 365 + NULL, 366 + }; 367 + 368 + static const struct attribute_group w1_ds2438_group = { 369 + .bin_attrs = w1_ds2438_bin_attrs, 370 + }; 371 + 372 + static const struct attribute_group *w1_ds2438_groups[] = { 373 + &w1_ds2438_group, 374 + NULL, 375 + }; 376 + 377 + static struct w1_family_ops w1_ds2438_fops = { 378 + .groups = w1_ds2438_groups, 379 + }; 380 + 381 + static struct w1_family w1_ds2438_family = { 382 + .fid = W1_FAMILY_DS2438, 383 + .fops = &w1_ds2438_fops, 384 + }; 385 + module_w1_family(w1_ds2438_family); 386 + 387 + MODULE_LICENSE("GPL"); 388 + MODULE_AUTHOR("Mariusz Bialonczyk <manio@skyboo.net>"); 389 + MODULE_DESCRIPTION("1-wire driver for Maxim/Dallas DS2438 Smart Battery Monitor"); 390 + MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2438));
+6 -4
drivers/w1/slaves/w1_ds2760.h
··· 24 24 #define DS2760_DATA_SIZE 0x40 25 25 26 26 #define DS2760_PROTECTION_REG 0x00 27 + 27 28 #define DS2760_STATUS_REG 0x01 28 - #define DS2760_STATUS_IE (1 << 2) 29 - #define DS2760_STATUS_SWEN (1 << 3) 30 - #define DS2760_STATUS_RNAOP (1 << 4) 31 - #define DS2760_STATUS_PMOD (1 << 5) 29 + #define DS2760_STATUS_IE (1 << 2) 30 + #define DS2760_STATUS_SWEN (1 << 3) 31 + #define DS2760_STATUS_RNAOP (1 << 4) 32 + #define DS2760_STATUS_PMOD (1 << 5) 33 + 32 34 #define DS2760_EEPROM_REG 0x07 33 35 #define DS2760_SPECIAL_FEATURE_REG 0x08 34 36 #define DS2760_VOLTAGE_MSB 0x0c
-1
drivers/w1/w1.c
··· 29 29 #include <linux/atomic.h> 30 30 31 31 #include "w1.h" 32 - #include "w1_log.h" 33 32 #include "w1_int.h" 34 33 #include "w1_family.h" 35 34 #include "w1_netlink.h"
+1
drivers/w1/w1_family.h
··· 29 29 #define W1_COUNTER_DS2423 0x1D 30 30 #define W1_THERM_DS1822 0x22 31 31 #define W1_EEPROM_DS2433 0x23 32 + #define W1_FAMILY_DS2438 0x26 32 33 #define W1_THERM_DS18B20 0x28 33 34 #define W1_FAMILY_DS2408 0x29 34 35 #define W1_EEPROM_DS2431 0x2D
-1
drivers/w1/w1_int.c
··· 22 22 #include <linux/moduleparam.h> 23 23 24 24 #include "w1.h" 25 - #include "w1_log.h" 26 25 #include "w1_netlink.h" 27 26 #include "w1_int.h" 28 27
-1
drivers/w1/w1_io.c
··· 19 19 #include <linux/module.h> 20 20 21 21 #include "w1.h" 22 - #include "w1_log.h" 23 22 24 23 static int w1_delay_parm = 1; 25 24 module_param_named(delay_coef, w1_delay_parm, int, 0);
-31
drivers/w1/w1_log.h
··· 1 - /* 2 - * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> 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 - 15 - #ifndef __W1_LOG_H 16 - #define __W1_LOG_H 17 - 18 - #define DEBUG 19 - 20 - #ifdef W1_DEBUG 21 - # define assert(expr) do {} while (0) 22 - #else 23 - # define assert(expr) \ 24 - if(unlikely(!(expr))) { \ 25 - pr_err("Assertion failed! %s,%s,%s,line=%d\n", \ 26 - #expr, __FILE__, __func__, __LINE__); \ 27 - } 28 - #endif 29 - 30 - #endif /* __W1_LOG_H */ 31 -
+1 -4
drivers/w1/w1_netlink.c
··· 18 18 #include <linux/connector.h> 19 19 20 20 #include "w1.h" 21 - #include "w1_log.h" 22 21 #include "w1_netlink.h" 23 22 24 23 #if defined(CONFIG_W1_CON) && (defined(CONFIG_CONNECTOR) || (defined(CONFIG_CONNECTOR_MODULE) && defined(CONFIG_W1_MODULE))) 25 - 26 - #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 27 24 28 25 /* Bundle together everything required to process a request in one memory 29 26 * allocation. ··· 595 598 sizeof(struct w1_netlink_msg) + 596 599 sizeof(struct w1_netlink_cmd)); 597 600 } 598 - reply_size = MIN(CONNECTOR_MAX_MSG_SIZE, reply_size); 601 + reply_size = min(CONNECTOR_MAX_MSG_SIZE, reply_size); 599 602 600 603 /* allocate space for the block, a copy of the original message, 601 604 * one node per cmd to point into the original message,
+9 -6
drivers/zorro/zorro-driver.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/zorro.h> 16 16 17 + #include "zorro.h" 18 + 17 19 18 20 /** 19 21 * zorro_match_device - Tell if a Zorro device structure has a matching ··· 163 161 } 164 162 165 163 struct bus_type zorro_bus_type = { 166 - .name = "zorro", 167 - .dev_name = "zorro", 168 - .match = zorro_bus_match, 169 - .uevent = zorro_uevent, 170 - .probe = zorro_device_probe, 171 - .remove = zorro_device_remove, 164 + .name = "zorro", 165 + .dev_name = "zorro", 166 + .dev_groups = zorro_device_attribute_groups, 167 + .match = zorro_bus_match, 168 + .uevent = zorro_uevent, 169 + .probe = zorro_device_probe, 170 + .remove = zorro_device_remove, 172 171 }; 173 172 EXPORT_SYMBOL(zorro_bus_type); 174 173
+40 -36
drivers/zorro/zorro-sysfs.c
··· 23 23 24 24 /* show configuration fields */ 25 25 #define zorro_config_attr(name, field, format_string) \ 26 - static ssize_t \ 27 - show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ 26 + static ssize_t name##_show(struct device *dev, \ 27 + struct device_attribute *attr, char *buf) \ 28 28 { \ 29 29 struct zorro_dev *z; \ 30 30 \ 31 31 z = to_zorro_dev(dev); \ 32 32 return sprintf(buf, format_string, z->field); \ 33 33 } \ 34 - static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 34 + static DEVICE_ATTR_RO(name); 35 35 36 36 zorro_config_attr(id, id, "0x%08x\n"); 37 37 zorro_config_attr(type, rom.er_Type, "0x%02x\n"); 38 38 zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); 39 39 zorro_config_attr(slotsize, slotsize, "0x%04x\n"); 40 40 41 - static ssize_t 42 - show_serial(struct device *dev, struct device_attribute *attr, char *buf) 41 + static ssize_t serial_show(struct device *dev, struct device_attribute *attr, 42 + char *buf) 43 43 { 44 44 struct zorro_dev *z; 45 45 46 46 z = to_zorro_dev(dev); 47 47 return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber)); 48 48 } 49 + static DEVICE_ATTR_RO(serial); 49 50 50 - static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); 51 - 52 - static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf) 51 + static ssize_t resource_show(struct device *dev, struct device_attribute *attr, 52 + char *buf) 53 53 { 54 54 struct zorro_dev *z = to_zorro_dev(dev); 55 55 ··· 58 58 (unsigned long)zorro_resource_end(z), 59 59 zorro_resource_flags(z)); 60 60 } 61 + static DEVICE_ATTR_RO(resource); 61 62 62 - static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); 63 + static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 64 + char *buf) 65 + { 66 + struct zorro_dev *z = to_zorro_dev(dev); 67 + 68 + return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); 69 + } 70 + static DEVICE_ATTR_RO(modalias); 71 + 72 + static struct attribute *zorro_device_attrs[] = { 73 + &dev_attr_id.attr, 74 + &dev_attr_type.attr, 75 + &dev_attr_serial.attr, 76 + &dev_attr_slotaddr.attr, 77 + &dev_attr_slotsize.attr, 78 + &dev_attr_resource.attr, 79 + &dev_attr_modalias.attr, 80 + NULL 81 + }; 63 82 64 83 static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, 65 84 struct bin_attribute *bin_attr, ··· 107 88 .read = zorro_read_config, 108 89 }; 109 90 110 - static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 111 - char *buf) 112 - { 113 - struct zorro_dev *z = to_zorro_dev(dev); 91 + static struct bin_attribute *zorro_device_bin_attrs[] = { 92 + &zorro_config_attr, 93 + NULL 94 + }; 114 95 115 - return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); 116 - } 96 + static const struct attribute_group zorro_device_attr_group = { 97 + .attrs = zorro_device_attrs, 98 + .bin_attrs = zorro_device_bin_attrs, 99 + }; 117 100 118 - static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); 119 - 120 - int zorro_create_sysfs_dev_files(struct zorro_dev *z) 121 - { 122 - struct device *dev = &z->dev; 123 - int error; 124 - 125 - /* current configuration's attributes */ 126 - if ((error = device_create_file(dev, &dev_attr_id)) || 127 - (error = device_create_file(dev, &dev_attr_type)) || 128 - (error = device_create_file(dev, &dev_attr_serial)) || 129 - (error = device_create_file(dev, &dev_attr_slotaddr)) || 130 - (error = device_create_file(dev, &dev_attr_slotsize)) || 131 - (error = device_create_file(dev, &dev_attr_resource)) || 132 - (error = device_create_file(dev, &dev_attr_modalias)) || 133 - (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) 134 - return error; 135 - 136 - return 0; 137 - } 138 - 101 + const struct attribute_group *zorro_device_attribute_groups[] = { 102 + &zorro_device_attr_group, 103 + NULL 104 + };
-3
drivers/zorro/zorro.c
··· 197 197 put_device(&z->dev); 198 198 continue; 199 199 } 200 - error = zorro_create_sysfs_dev_files(z); 201 - if (error) 202 - dev_err(&z->dev, "Error creating sysfs files\n"); 203 200 } 204 201 205 202 /* Mark all available Zorro II memory */
+1 -2
drivers/zorro/zorro.h
··· 5 5 static inline void zorro_name_device(struct zorro_dev *dev) { } 6 6 #endif 7 7 8 - extern int zorro_create_sysfs_dev_files(struct zorro_dev *z); 9 - 8 + extern const struct attribute_group *zorro_device_attribute_groups[];
+86
fs/char_dev.c
··· 471 471 return 0; 472 472 } 473 473 474 + /** 475 + * cdev_set_parent() - set the parent kobject for a char device 476 + * @p: the cdev structure 477 + * @kobj: the kobject to take a reference to 478 + * 479 + * cdev_set_parent() sets a parent kobject which will be referenced 480 + * appropriately so the parent is not freed before the cdev. This 481 + * should be called before cdev_add. 482 + */ 483 + void cdev_set_parent(struct cdev *p, struct kobject *kobj) 484 + { 485 + WARN_ON(!kobj->state_initialized); 486 + p->kobj.parent = kobj; 487 + } 488 + 489 + /** 490 + * cdev_device_add() - add a char device and it's corresponding 491 + * struct device, linkink 492 + * @dev: the device structure 493 + * @cdev: the cdev structure 494 + * 495 + * cdev_device_add() adds the char device represented by @cdev to the system, 496 + * just as cdev_add does. It then adds @dev to the system using device_add 497 + * The dev_t for the char device will be taken from the struct device which 498 + * needs to be initialized first. This helper function correctly takes a 499 + * reference to the parent device so the parent will not get released until 500 + * all references to the cdev are released. 501 + * 502 + * This helper uses dev->devt for the device number. If it is not set 503 + * it will not add the cdev and it will be equivalent to device_add. 504 + * 505 + * This function should be used whenever the struct cdev and the 506 + * struct device are members of the same structure whose lifetime is 507 + * managed by the struct device. 508 + * 509 + * NOTE: Callers must assume that userspace was able to open the cdev and 510 + * can call cdev fops callbacks at any time, even if this function fails. 511 + */ 512 + int cdev_device_add(struct cdev *cdev, struct device *dev) 513 + { 514 + int rc = 0; 515 + 516 + if (dev->devt) { 517 + cdev_set_parent(cdev, &dev->kobj); 518 + 519 + rc = cdev_add(cdev, dev->devt, 1); 520 + if (rc) 521 + return rc; 522 + } 523 + 524 + rc = device_add(dev); 525 + if (rc) 526 + cdev_del(cdev); 527 + 528 + return rc; 529 + } 530 + 531 + /** 532 + * cdev_device_del() - inverse of cdev_device_add 533 + * @dev: the device structure 534 + * @cdev: the cdev structure 535 + * 536 + * cdev_device_del() is a helper function to call cdev_del and device_del. 537 + * It should be used whenever cdev_device_add is used. 538 + * 539 + * If dev->devt is not set it will not remove the cdev and will be equivalent 540 + * to device_del. 541 + * 542 + * NOTE: This guarantees that associated sysfs callbacks are not running 543 + * or runnable, however any cdevs already open will remain and their fops 544 + * will still be callable even after this function returns. 545 + */ 546 + void cdev_device_del(struct cdev *cdev, struct device *dev) 547 + { 548 + device_del(dev); 549 + if (dev->devt) 550 + cdev_del(cdev); 551 + } 552 + 474 553 static void cdev_unmap(dev_t dev, unsigned count) 475 554 { 476 555 kobj_unmap(cdev_map, dev, count); ··· 561 482 * 562 483 * cdev_del() removes @p from the system, possibly freeing the structure 563 484 * itself. 485 + * 486 + * NOTE: This guarantees that cdev device will no longer be able to be 487 + * opened, however any cdevs already open will remain and their fops will 488 + * still be callable even after cdev_del returns. 564 489 */ 565 490 void cdev_del(struct cdev *p) 566 491 { ··· 653 570 EXPORT_SYMBOL(cdev_alloc); 654 571 EXPORT_SYMBOL(cdev_del); 655 572 EXPORT_SYMBOL(cdev_add); 573 + EXPORT_SYMBOL(cdev_set_parent); 574 + EXPORT_SYMBOL(cdev_device_add); 575 + EXPORT_SYMBOL(cdev_device_del); 656 576 EXPORT_SYMBOL(__register_chrdev); 657 577 EXPORT_SYMBOL(__unregister_chrdev);
+5
include/linux/cdev.h
··· 4 4 #include <linux/kobject.h> 5 5 #include <linux/kdev_t.h> 6 6 #include <linux/list.h> 7 + #include <linux/device.h> 7 8 8 9 struct file_operations; 9 10 struct inode; ··· 26 25 void cdev_put(struct cdev *p); 27 26 28 27 int cdev_add(struct cdev *, dev_t, unsigned); 28 + 29 + void cdev_set_parent(struct cdev *p, struct kobject *kobj); 30 + int cdev_device_add(struct cdev *cdev, struct device *dev); 31 + void cdev_device_del(struct cdev *cdev, struct device *dev); 29 32 30 33 void cdev_del(struct cdev *); 31 34
+29
include/linux/fpga/altera-pr-ip-core.h
··· 1 + /* 2 + * Driver for Altera Partial Reconfiguration IP Core 3 + * 4 + * Copyright (C) 2016 Intel Corporation 5 + * 6 + * Based on socfpga-a10.c Copyright (C) 2015-2016 Altera Corporation 7 + * by Alan Tull <atull@opensource.altera.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify it 10 + * under the terms and conditions of the GNU General Public License, 11 + * version 2, as published by the Free Software Foundation. 12 + * 13 + * This program is distributed in the hope it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program. If not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + 22 + #ifndef _ALT_PR_IP_CORE_H 23 + #define _ALT_PR_IP_CORE_H 24 + #include <linux/io.h> 25 + 26 + int alt_pr_register(struct device *dev, void __iomem *reg_base); 27 + int alt_pr_unregister(struct device *dev); 28 + 29 + #endif /* _ALT_PR_IP_CORE_H */
+4
include/linux/fpga/fpga-mgr.h
··· 70 70 */ 71 71 #define FPGA_MGR_PARTIAL_RECONFIG BIT(0) 72 72 #define FPGA_MGR_EXTERNAL_CONFIG BIT(1) 73 + #define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2) 73 74 74 75 /** 75 76 * struct fpga_image_info - information specific to a FPGA image 76 77 * @flags: boolean flags as defined above 77 78 * @enable_timeout_us: maximum time to enable traffic through bridge (uSec) 78 79 * @disable_timeout_us: maximum time to disable traffic through bridge (uSec) 80 + * @config_complete_timeout_us: maximum time for FPGA to switch to operating 81 + * status in the write_complete op. 79 82 */ 80 83 struct fpga_image_info { 81 84 u32 flags; 82 85 u32 enable_timeout_us; 83 86 u32 disable_timeout_us; 87 + u32 config_complete_timeout_us; 84 88 }; 85 89 86 90 /**
+23 -8
include/linux/hyperv.h
··· 491 491 u32 child_relid; 492 492 } __packed; 493 493 494 + static inline u32 495 + hv_ringbuffer_pending_size(const struct hv_ring_buffer_info *rbi) 496 + { 497 + return rbi->ring_buffer->pending_send_sz; 498 + } 499 + 494 500 /* 495 501 * Request Offer -- no parameters, SynIC message contains the partition ID 496 502 * Set Snoop -- no parameters, SynIC message contains the partition ID ··· 530 524 u32 target_vp; 531 525 532 526 /* 533 - * The upstream ring buffer begins at offset zero in the memory 534 - * described by RingBufferGpadlHandle. The downstream ring buffer 535 - * follows it at this offset (in pages). 536 - */ 527 + * The upstream ring buffer begins at offset zero in the memory 528 + * described by RingBufferGpadlHandle. The downstream ring buffer 529 + * follows it at this offset (in pages). 530 + */ 537 531 u32 downstream_ringbuffer_pageoffset; 538 532 539 533 /* User-specific data to be passed along to the server endpoint. */ ··· 1019 1013 u32 recv_ringbuffersize, 1020 1014 void *userdata, 1021 1015 u32 userdatalen, 1022 - void(*onchannel_callback)(void *context), 1016 + void (*onchannel_callback)(void *context), 1023 1017 void *context); 1024 1018 1025 1019 extern void vmbus_close(struct vmbus_channel *channel); ··· 1160 1154 { 1161 1155 return dev_get_drvdata(&dev->device); 1162 1156 } 1157 + 1158 + struct hv_ring_buffer_debug_info { 1159 + u32 current_interrupt_mask; 1160 + u32 current_read_index; 1161 + u32 current_write_index; 1162 + u32 bytes_avail_toread; 1163 + u32 bytes_avail_towrite; 1164 + }; 1165 + 1166 + void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info, 1167 + struct hv_ring_buffer_debug_info *debug_info); 1163 1168 1164 1169 /* Vmbus interface */ 1165 1170 #define vmbus_driver_register(driver) \ ··· 1445 1428 char *log_msg; 1446 1429 uuid_le data; 1447 1430 struct vmbus_channel *channel; 1448 - void (*callback) (void *context); 1431 + void (*callback)(void *context); 1449 1432 }; 1450 1433 1451 1434 #define MAX_SRV_VER 0x7ffffff ··· 1521 1504 cached_write_sz = hv_get_cached_bytes_to_write(rbi); 1522 1505 if (cached_write_sz < pending_sz) 1523 1506 vmbus_setevent(channel); 1524 - 1525 - return; 1526 1507 } 1527 1508 1528 1509 /*
+8 -5
include/linux/uio_driver.h
··· 23 23 /** 24 24 * struct uio_mem - description of a UIO memory region 25 25 * @name: name of the memory region for identification 26 - * @addr: address of the device's memory (phys_addr is used since 27 - * addr can be logical, virtual, or physical & phys_addr_t 28 - * should always be large enough to handle any of the 29 - * address types) 30 - * @size: size of IO 26 + * @addr: address of the device's memory rounded to page 27 + * size (phys_addr is used since addr can be 28 + * logical, virtual, or physical & phys_addr_t 29 + * should always be large enough to handle any of 30 + * the address types) 31 + * @offs: offset of device memory within the page 32 + * @size: size of IO (multiple of page size) 31 33 * @memtype: type of memory addr points to 32 34 * @internal_addr: ioremap-ped version of addr, for driver internal use 33 35 * @map: for use by the UIO core only. ··· 37 35 struct uio_mem { 38 36 const char *name; 39 37 phys_addr_t addr; 38 + unsigned long offs; 40 39 resource_size_t size; 41 40 int memtype; 42 41 void __iomem *internal_addr;
+11 -1
include/linux/vme.h
··· 92 92 #define VME_SLOT_ALL -2 93 93 94 94 /** 95 - * Structure representing a VME device 95 + * struct vme_dev - Structure representing a VME device 96 96 * @num: The device number 97 97 * @bridge: Pointer to the bridge device this device is on 98 98 * @dev: Internal device structure ··· 107 107 struct list_head bridge_list; 108 108 }; 109 109 110 + /** 111 + * struct vme_driver - Structure representing a VME driver 112 + * @name: Driver name, should be unique among VME drivers and usually the same 113 + * as the module name. 114 + * @match: Callback used to determine whether probe should be run. 115 + * @probe: Callback for device binding, called when new device is detected. 116 + * @remove: Callback, called on device removal. 117 + * @driver: Underlying generic device driver structure. 118 + * @devices: List of VME devices (struct vme_dev) associated with this driver. 119 + */ 110 120 struct vme_driver { 111 121 const char *name; 112 122 int (*match)(struct vme_dev *);
+42
include/misc/charlcd.h
··· 1 + /* 2 + * Character LCD driver for Linux 3 + * 4 + * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu> 5 + * Copyright (C) 2016-2017 Glider bvba 6 + * 7 + * This program is free software; you can redistribute it and/or 8 + * modify it under the terms of the GNU General Public License 9 + * as published by the Free Software Foundation; either version 10 + * 2 of the License, or (at your option) any later version. 11 + */ 12 + 13 + struct charlcd { 14 + const struct charlcd_ops *ops; 15 + const unsigned char *char_conv; /* Optional */ 16 + 17 + int ifwidth; /* 4-bit or 8-bit (default) */ 18 + int height; 19 + int width; 20 + int bwidth; /* Default set by charlcd_alloc() */ 21 + int hwidth; /* Default set by charlcd_alloc() */ 22 + 23 + void *drvdata; /* Set by charlcd_alloc() */ 24 + }; 25 + 26 + struct charlcd_ops { 27 + /* Required */ 28 + void (*write_cmd)(struct charlcd *lcd, int cmd); 29 + void (*write_data)(struct charlcd *lcd, int data); 30 + 31 + /* Optional */ 32 + void (*write_cmd_raw4)(struct charlcd *lcd, int cmd); /* 4-bit only */ 33 + void (*clear_fast)(struct charlcd *lcd); 34 + void (*backlight)(struct charlcd *lcd, int on); 35 + }; 36 + 37 + struct charlcd *charlcd_alloc(unsigned int drvdata_size); 38 + 39 + int charlcd_register(struct charlcd *lcd); 40 + int charlcd_unregister(struct charlcd *lcd); 41 + 42 + void charlcd_poke(struct charlcd *lcd);
+61
include/uapi/linux/aspeed-lpc-ctrl.h
··· 1 + /* 2 + * Copyright 2017 IBM Corp. 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * as published by the Free Software Foundation; either version 7 + * 2 of the License, or (at your option) any later version. 8 + */ 9 + 10 + #ifndef _UAPI_LINUX_ASPEED_LPC_CTRL_H 11 + #define _UAPI_LINUX_ASPEED_LPC_CTRL_H 12 + 13 + #include <linux/ioctl.h> 14 + #include <linux/types.h> 15 + 16 + /* Window types */ 17 + #define ASPEED_LPC_CTRL_WINDOW_FLASH 1 18 + #define ASPEED_LPC_CTRL_WINDOW_MEMORY 2 19 + 20 + /* 21 + * This driver provides a window for the host to access a BMC resource 22 + * across the BMC <-> Host LPC bus. 23 + * 24 + * window_type: The BMC resource that the host will access through the 25 + * window. BMC flash and BMC RAM. 26 + * 27 + * window_id: For each window type there may be multiple windows, 28 + * these are referenced by ID. 29 + * 30 + * flags: Reserved for future use, this field is expected to be 31 + * zeroed. 32 + * 33 + * addr: Address on the host LPC bus that the specified window should 34 + * be mapped. This address must be power of two aligned. 35 + * 36 + * offset: Offset into the BMC window that should be mapped to the 37 + * host (at addr). This must be a multiple of size. 38 + * 39 + * size: The size of the mapping. The smallest possible size is 64K. 40 + * This must be power of two aligned. 41 + * 42 + */ 43 + 44 + struct aspeed_lpc_ctrl_mapping { 45 + __u8 window_type; 46 + __u8 window_id; 47 + __u16 flags; 48 + __u32 addr; 49 + __u32 offset; 50 + __u32 size; 51 + }; 52 + 53 + #define __ASPEED_LPC_CTRL_IOCTL_MAGIC 0xb2 54 + 55 + #define ASPEED_LPC_CTRL_IOCTL_GET_SIZE _IOWR(__ASPEED_LPC_CTRL_IOCTL_MAGIC, \ 56 + 0x00, struct aspeed_lpc_ctrl_mapping) 57 + 58 + #define ASPEED_LPC_CTRL_IOCTL_MAP _IOW(__ASPEED_LPC_CTRL_IOCTL_MAGIC, \ 59 + 0x01, struct aspeed_lpc_ctrl_mapping) 60 + 61 + #endif /* _UAPI_LINUX_ASPEED_LPC_CTRL_H */
+19
include/uapi/linux/pps.h
··· 55 55 __s32 nsec; 56 56 __u32 flags; 57 57 }; 58 + 59 + struct pps_ktime_compat { 60 + __s64 sec; 61 + __s32 nsec; 62 + __u32 flags; 63 + } __attribute__((packed, aligned(4))); 58 64 #define PPS_TIME_INVALID (1<<0) /* used to specify timeout==NULL */ 59 65 60 66 struct pps_kinfo { ··· 69 63 struct pps_ktime assert_tu; /* time of assert event */ 70 64 struct pps_ktime clear_tu; /* time of clear event */ 71 65 int current_mode; /* current mode bits */ 66 + }; 67 + 68 + struct pps_kinfo_compat { 69 + __u32 assert_sequence; /* seq. num. of assert event */ 70 + __u32 clear_sequence; /* seq. num. of clear event */ 71 + struct pps_ktime_compat assert_tu; /* time of assert event */ 72 + struct pps_ktime_compat clear_tu; /* time of clear event */ 73 + int current_mode; /* current mode bits */ 72 74 }; 73 75 74 76 struct pps_kparams { ··· 126 112 struct pps_fdata { 127 113 struct pps_kinfo info; 128 114 struct pps_ktime timeout; 115 + }; 116 + 117 + struct pps_fdata_compat { 118 + struct pps_kinfo_compat info; 119 + struct pps_ktime_compat timeout; 129 120 }; 130 121 131 122 struct pps_bind_args {
-2
samples/mei/TODO
··· 1 - TODO: 2 - - Cleanup and split the timer function
+1 -1
scripts/ver_linux
··· 1 - #!/bin/awk -f 1 + #!/usr/bin/awk -f 2 2 # Before running this script please ensure that your PATH is 3 3 # typical as you use for compilation/installation. I use 4 4 # /bin /sbin /usr/bin /usr/sbin /usr/local/bin, but it may