From patchwork Sun Mar 17 19:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13594826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD381C54E60 for ; Sun, 17 Mar 2024 19:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/9TOzX5hJI33u8eB/6Ch87kDa6hIdZG/jWQFRSuCOtc=; b=n50qmHUfSuPVCN WCcKFymnyvhAHjjXkfoHV/qGFokiBRQO5hgwT1aouDr7YEVAjhfKkWUxS6mUcC8GR7UDAMV3KS3Wn Ot9kSjWPcf/IBo5huHBMfPrcWhxUAfgVzB9FFIEOcXzFV1u5euixGqSHLqPpDNRgQnNtb4Q34/rmd +6cvqhNy6lxfw/pPXAlphnNVNvBxk9fyqB01qy4MHiOqsrNF6UPeajL3hpeLBQA0I1SxQr6z8Q9Kj zkNKWg9mrFrO7sALIgBQEGuJWW08E5zl4+JQpFRbT+0u6zog8yYmIkKoK/W8BdTGY3Kb5gUtTEi4W 3qn1omILAyc4aD63n4Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwKl-00000006Dzo-2vUO; Sun, 17 Mar 2024 19:38:15 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwKh-00000006DyO-3uc8 for linux-arm-kernel@lists.infradead.org; Sun, 17 Mar 2024 19:38:14 +0000 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-29c5f8bc830so2415219a91.2 for ; Sun, 17 Mar 2024 12:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704291; x=1711309091; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XAFdZ643wkelI8hZPnf28UKtzzWxeqJSxohoYBvzlpg=; b=gKVRCR5/NU0pTQZjwJEpFvc2bytuAoio06E/QXMpQKdms2HL/qDg2Nl9+DUmQaWJ0t dViIMs6qq9t8uDJg9SdwvmR/bw9iovYcGvX7eWNNc/wsnipN1rSQ4wIqJwzSMOHt8rMq Ldvn/z0Gc3r7f8zsYS/AbxTeZTGTqvO2YuRFZNHfsFDkvE1+En41HjyzctikGCZvWLig l7PUVFjw3kPeqUuuCHeFE/grUbL9PgMFrnsKUsPr1iat39KxTXfbA8UEIJv/tJc4NUTr +5uREcrxIcgPUM4w88S0BJtWjYPPQ6li1sBazNEN9J+sswJ3piy3zoU76pRtBwDkNMQI g1Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710704291; x=1711309091; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XAFdZ643wkelI8hZPnf28UKtzzWxeqJSxohoYBvzlpg=; b=rmmCJtnSfNyk93/gh4QAJSbe9++RdX8PCqLBbhYAzcZyihsRJxDlcRXnVUfVzNiaYE Mjqi7OvIap5s2C4Ztl6yGG2sARTIt5EYv9sZ7lXaMRQw4pHwBfUTEouec7R4ZmNDn2JT IBu9OwrCEMtDEc2J0P6Gtt4fRla7fsAAHi6qsHZfPW6oe3U3hV2655+G452Iia7X6nx7 ZaolQHbCLTAdk0sjl33ItDs1Y1EIuYTQfGLOgVrMdrtx6GddpVkR5rvGXI5wfk1Y7R9o WmXHRUV6I3H22+Gy2CkhT7GS2bYujRTWRze3e4/NImpX4REiidZTah8A4EFMKLzcGLMW 8V3A== X-Forwarded-Encrypted: i=1; AJvYcCV1oAAKJRtvdCt5rzqi3WB5uuVOdScz2381o4RTcfZZ7nwWhQuayBTmjVT1g10wftAG6NPz/2d8MYWz0Kt5RaHLOxNbzUhE7plmqtkHePptD6Kphqo= X-Gm-Message-State: AOJu0YwHszNNwIuGWJyygTxK/UVtyTl87XAv+AkoyjrdJxIklwkewWAE DfQZwljbAJ8oLLxOGZm671QEAlFRGZVytLqmpe1wQsubaMTdhwKN X-Google-Smtp-Source: AGHT+IGIMfDbF9VDPxpzPhgHWGmVrvu7kV7iVi2cPqw22K30WUzkmMxnJYuAGqmR7ul921En552HNg== X-Received: by 2002:a17:90a:88d:b0:29d:e70f:7240 with SMTP id v13-20020a17090a088d00b0029de70f7240mr6358733pjc.11.1710704290554; Sun, 17 Mar 2024 12:38:10 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id st6-20020a17090b1fc600b0029bbdc920besm6125995pjb.44.2024.03.17.12.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 12:38:10 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org (open list) Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, lorforlinux@beagleboard.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Vaishnav M A , Mark Brown , Johan Hovold , Alex Elder , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS INSTRUMENTS K3 ARCHITECTURE), linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM), Vaishnav M A Subject: [PATCH v4 1/5] dt-bindings: misc: Add mikrobus-connector Date: Mon, 18 Mar 2024 01:07:09 +0530 Message-ID: <20240317193714.403132-2-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com> References: <20240317193714.403132-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_123812_315401_A606471D X-CRM114-Status: GOOD ( 19.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add DT bindings for mikroBUS interface. MikroBUS is an open standard developed by MikroElektronika for connecting add-on boards to microcontrollers or microprocessors. mikroBUS is a connector and does not have a controller. Instead the software is responsible for identification of board and setting up / registering uart, spi, i2c, pwm and other buses. Thus it needs a way to get uart, spi, i2c, pwm and gpio controllers / adapters. A mikroBUS addon board is free to leave some of the pins unused which are marked as NC or Not Connected. Some of the pins might need to be configured as GPIOs deviating from their reserved purposes Eg: SHT15 Click where the SCL and SDA Pins need to be configured as GPIOs for the driver (drivers/hwmon/sht15.c) to work. For some add-on boards the driver may not take care of some additional signals like reset/wake-up/other. Eg: ENC28J60 click where the reset line (RST pin on the mikrobus port) needs to be pulled high. Here's the list of pins in mikroBUS connector: Analog - AN Reset - RST SPI Chip Select - CS SPI Clock - SCK SPI Master Input Slave Output - MISO SPI Master Output Slave Input - MOSI VCC-3.3V power - +3.3V Reference Ground - GND PWM - PWM output INT - Hardware Interrupt RX - UART Receive TX - UART Transmit SCL - I2C Clock SDA - I2C Data +5V - VCC-5V power GND - Reference Ground Additionally, some new mikroBUS boards contain 1-wire EEPROM that contains a manifest to describe the addon board to provide plug and play capabilities. Link: https://www.mikroe.com/mikrobus Link: https://download.mikroe.com/documents/standards/mikrobus/mikrobus-standard-specification-v200.pdf mikroBUS specification Link: https://www.mikroe.com/sht1x-click SHT15 Click Link: https://www.mikroe.com/eth-click ENC28J60 Click Link: https://www.mikroe.com/clickid ClickID Co-developed-by: Vaishnav M A Signed-off-by: Vaishnav M A Signed-off-by: Ayush Singh --- .../connector/mikrobus-connector.yaml | 113 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 119 insertions(+) create mode 100644 Documentation/devicetree/bindings/connector/mikrobus-connector.yaml diff --git a/Documentation/devicetree/bindings/connector/mikrobus-connector.yaml b/Documentation/devicetree/bindings/connector/mikrobus-connector.yaml new file mode 100644 index 000000000000..ee3736add41c --- /dev/null +++ b/Documentation/devicetree/bindings/connector/mikrobus-connector.yaml @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/connector/mikrobus-connector.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: mikroBUS add-on board socket + +maintainers: + - Ayush Singh + +properties: + compatible: + const: mikrobus-connector + + pinctrl-0: true + pinctrl-1: true + pinctrl-2: true + pinctrl-3: true + pinctrl-4: true + pinctrl-5: true + pinctrl-6: true + pinctrl-7: true + pinctrl-8: true + + pinctrl-names: + items: + - const: default + - const: pwm_default + - const: pwm_gpio + - const: uart_default + - const: uart_gpio + - const: i2c_default + - const: i2c_gpio + - const: spi_default + - const: spi_gpio + + mikrobus-gpios: + minItems: 11 + maxItems: 12 + + i2c-adapter: + description: i2c adapter attached to the mikrobus socket. + $ref: /schemas/types.yaml#/definitions/phandle + + spi-controller: + description: spi bus number of the spi-master attached to the mikrobus socket. + $ref: /schemas/types.yaml#/definitions/phandle + + uart: + description: uart port attached to the mikrobus socket + $ref: /schemas/types.yaml#/definitions/phandle + + pwms: + description: the pwm-controller corresponding to the mikroBUS PWM pin. + maxItems: 1 + + spi-cs: + description: spi chip-select numbers corresponding to the chip-selects on the mikrobus socket. + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - description: chip select corresponding to CS pin + - description: chip select corresponding to RST pin + +required: + - compatible + - pinctrl-0 + - pinctrl-1 + - pinctrl-2 + - pinctrl-3 + - pinctrl-4 + - pinctrl-5 + - pinctrl-6 + - pinctrl-7 + - pinctrl-8 + - i2c-adapter + - spi-controller + - spi-cs + - uart + - pwms + - mikrobus-gpios + +additionalProperties: false + +examples: + - | + #include + + mikrobus { + compatible = "mikrobus-connector"; + pinctrl-names = "default", "pwm_default", "pwm_gpio","uart_default", "uart_gpio", "i2c_default", + "i2c_gpio", "spi_default", "spi_gpio"; + pinctrl-0 = <&P2_03_gpio_input_pin &P1_04_gpio_pin &P1_02_gpio_pin>; + pinctrl-1 = <&P2_01_pwm_pin>; + pinctrl-2 = <&P2_01_gpio_pin>; + pinctrl-3 = <&P2_05_uart_pin &P2_07_uart_pin>; + pinctrl-4 = <&P2_05_gpio_pin &P2_07_gpio_pin>; + pinctrl-5 = <&P2_09_i2c_pin &P2_11_i2c_pin>; + pinctrl-6 = <&P2_09_gpio_pin &P2_11_gpio_pin>; + pinctrl-7 = <&P1_12_spi_pin &P1_10_spi_pin &P1_08_spi_sclk_pin &P1_06_spi_cs_pin>; + pinctrl-8 = <&P1_12_gpio_pin &P1_10_gpio_pin &P1_08_gpio_pin &P1_06_gpio_pin>; + pwms = <&ehrpwm1 0 500000 0>; + i2c-adapter = <&i2c1>; + spi-controller = <&spi1>; + spi-cs = <0 1>; + uart = <&uart1>; + mikrobus-gpios = <&gpio1 18 GPIO_ACTIVE_HIGH>, <&gpio0 23 GPIO_ACTIVE_HIGH>, + <&gpio0 30 GPIO_ACTIVE_HIGH>, <&gpio0 31 GPIO_ACTIVE_HIGH>, + <&gpio0 15 GPIO_ACTIVE_HIGH>, <&gpio0 14 GPIO_ACTIVE_HIGH>, + <&gpio0 4 GPIO_ACTIVE_HIGH>, <&gpio0 3 GPIO_ACTIVE_HIGH>, + <&gpio0 2 GPIO_ACTIVE_HIGH>, <&gpio0 5 GPIO_ACTIVE_HIGH>, + <&gpio2 25 GPIO_ACTIVE_HIGH>, <&gpio2 3 GPIO_ACTIVE_HIGH>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 375d34363777..69418a058c6b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14767,6 +14767,12 @@ M: Oliver Neukum S: Maintained F: drivers/usb/image/microtek.* +MIKROBUS +M: Ayush Singh +M: Vaishnav M A +S: Maintained +F: Documentation/devicetree/bindings/misc/mikrobus-connector.yaml + MIKROTIK CRS3XX 98DX3236 BOARD SUPPORT M: Luka Kovacic M: Luka Perkov From patchwork Sun Mar 17 19:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13594827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40FF8C54E67 for ; Sun, 17 Mar 2024 19:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K0EjaGMhV4MMeywDJexlVaHsSWMs30pxRutO82B9IVs=; b=ng9ayuqzLAiQge viivhICxYWSYK4dW6ybuDbBeIYt2emNiCR16+9dGhE3XYbDccNoXvnxVUOycwmCuiI5gF4Eq/rMc/ +07SmqBiz39E3hTWkjLc+uEba2ZEfQm/TT4ZO2s4/RxniY0lLRshsGEO+WqqbNazRSxAB0i6a/SKm 4CHj2nB8KK5w3nsgI/b2H3s4qDT3fg9uNiUCd7db72zy1Wu+NczPtu9+LkT3IGu7N7qSpbiLI32RU YbpC8sn6Z8XwSzw7G6od0TAE+Ic67ZVuUXKaDebAf7R5fGeq1f1b3nVqVZhw7nVbr+PTnUPtVqN8I F83B8V13Whqbcli4vNXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwKt-00000006E3E-3sYA; Sun, 17 Mar 2024 19:38:24 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwKp-00000006E1L-4BIf for linux-arm-kernel@lists.infradead.org; Sun, 17 Mar 2024 19:38:21 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e6b54a28ebso3741404b3a.2 for ; Sun, 17 Mar 2024 12:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704299; x=1711309099; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UinOTZiM3YNMDKxNGnpGam2fV1kcoN0T5SiTjM6PDTw=; b=RuPjGYTqpMf5e2SKZGqUthAtPwmoxv9jFQ+UYlC6541WLMDHJl7Tdr4x1xIxqZpVvl oP/cFHcivR4eIPI6q35Eo+i0hSZoxMSpf/CUCPqlb0U+jXrJV7CUafCW8CNuAMA1hG2T 496w0oXEQc5I+ie5ZhF5GowpTLha/Bb9IWxBZlS15xrPGYp4ufCCcFV0iuulgvJfZJo9 2g4wX9K7jqDHwCFg8hEEeKejuiyKv/O/i8iAYMiMOS5TGQu0pJIcAiUM2Mp+q/husJLm 6lLBqezafUJ+JCRVXU2EYzXNMBLLRVchoK/jKVu8BgS20k6BNKov49oYdzaTHQkDhtv9 xAXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710704299; x=1711309099; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UinOTZiM3YNMDKxNGnpGam2fV1kcoN0T5SiTjM6PDTw=; b=IKSy/Ax3VIHLckwyrX+Qm2EPmfh18ZC/1wv2Wsa5vxwZTI+OfoZtpfCt1Ks0SiegHv umBD1Hi+xI8ghc+6/XyvkOA5weO6etUgl0qHe27M27U6Wh6S/YVNred3BT9SCz71H74X coTWELF6Zh7zKAxmFHqUie3H3i7w68mnQSGQFViHf3j4a3UzSEkO8CSaRw+pOUi2qPnt 9k4QM46wzK6Vs28ApuEjBnk0eoWxoyIC7QS6O2UPDaqC+3cPWNeKNu6usBvBjxgmAPDz V/ZfbwTYhollRGcRwHzqxedcO0B1D9OVxf9AMQgm0uM53INPjsyCUDaDBOcDbWVXEFx+ euFg== X-Forwarded-Encrypted: i=1; AJvYcCXPo6f9mu5WlnuzmumDvq1M4oAMIynyS2rR9kplQmb3Dxk+dI2BKg5iRSXDkhqPFXBO72tijz774X9d5T3brAuE5fT2QLJlC1rs2wzlTm9D/JjJrgo= X-Gm-Message-State: AOJu0YxBk2ZFJH/Ii+RWdiBVbrkFXnFLRptcEiTOHX8I0Ak1dxVFHMdV gt/W/zk7pqUeynExBOFBl9AMvztYT+mqtc69IUd/7wINt9CekRms X-Google-Smtp-Source: AGHT+IE8sZpYbXV9uhPR2rh6t5U9D1DtJZ3euRB90f52HReQDmvoMLV1WheMChqENzxjwSQDTpqS1A== X-Received: by 2002:a05:6a21:9202:b0:1a3:5090:7268 with SMTP id tl2-20020a056a21920200b001a350907268mr5531078pzb.47.1710704298563; Sun, 17 Mar 2024 12:38:18 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id st6-20020a17090b1fc600b0029bbdc920besm6125995pjb.44.2024.03.17.12.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 12:38:18 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org (open list) Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, lorforlinux@beagleboard.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Vaishnav M A , Mark Brown , Johan Hovold , Alex Elder , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS INSTRUMENTS K3 ARCHITECTURE), linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM) Subject: [PATCH v4 2/5] spi: Make of_find_spi_controller_by_node() available Date: Mon, 18 Mar 2024 01:07:10 +0530 Message-ID: <20240317193714.403132-3-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com> References: <20240317193714.403132-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_123820_118675_AFF00C76 X-CRM114-Status: GOOD ( 18.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DONOTMERGE This externalizes and exports the symbol of_find_spi_controller_by_node() from the SPI core akin to how of_find_i2c_adapter_by_node() is already available. As we will need this also for non-dynamic OF setups, we move it under a CONFIG_OF check. Signed-off-by: Ayush Singh --- drivers/spi/spi.c | 206 ++++++++++++++++++++-------------------- include/linux/spi/spi.h | 4 + 2 files changed, 108 insertions(+), 102 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ba4d3fde2054..9ec507d92f80 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2320,6 +2320,93 @@ void spi_flush_queue(struct spi_controller *ctlr) /*-------------------------------------------------------------------------*/ +static void spi_controller_release(struct device *dev) +{ + struct spi_controller *ctlr; + + ctlr = container_of(dev, struct spi_controller, dev); + kfree(ctlr); +} + +static struct class spi_master_class = { + .name = "spi_master", + .dev_release = spi_controller_release, + .dev_groups = spi_master_groups, +}; + +static ssize_t slave_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct spi_controller *ctlr = container_of(dev, struct spi_controller, + dev); + struct device *child; + + child = device_find_any_child(&ctlr->dev); + return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL); +} + +static ssize_t slave_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct spi_controller *ctlr = container_of(dev, struct spi_controller, + dev); + struct spi_device *spi; + struct device *child; + char name[32]; + int rc; + + rc = sscanf(buf, "%31s", name); + if (rc != 1 || !name[0]) + return -EINVAL; + + child = device_find_any_child(&ctlr->dev); + if (child) { + /* Remove registered slave */ + device_unregister(child); + put_device(child); + } + + if (strcmp(name, "(null)")) { + /* Register new slave */ + spi = spi_alloc_device(ctlr); + if (!spi) + return -ENOMEM; + + strscpy(spi->modalias, name, sizeof(spi->modalias)); + + rc = spi_add_device(spi); + if (rc) { + spi_dev_put(spi); + return rc; + } + } + + return count; +} + +static DEVICE_ATTR_RW(slave); + +static struct attribute *spi_slave_attrs[] = { + &dev_attr_slave.attr, + NULL, +}; + +static const struct attribute_group spi_slave_group = { + .attrs = spi_slave_attrs, +}; + +static const struct attribute_group *spi_slave_groups[] = { + &spi_controller_statistics_group, + &spi_slave_group, + NULL, +}; + +static struct class spi_slave_class = { + .name = "spi_slave", + .dev_release = spi_controller_release, + .dev_groups = spi_slave_groups, +}; + #if defined(CONFIG_OF) static void of_spi_parse_dt_cs_delay(struct device_node *nc, struct spi_delay *delay, const char *prop) @@ -2543,6 +2630,23 @@ static void of_register_spi_devices(struct spi_controller *ctlr) } } } + +/* The spi controllers are not using spi_bus, so we find it with another way */ +struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) +{ + struct device *dev; + + dev = class_find_device_by_of_node(&spi_master_class, node); + if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) + dev = class_find_device_by_of_node(&spi_slave_class, node); + if (!dev) + return NULL; + + /* Reference got in class_find_device */ + return container_of(dev, struct spi_controller, dev); +} +EXPORT_SYMBOL_GPL(of_find_spi_controller_by_node); + #else static void of_register_spi_devices(struct spi_controller *ctlr) { } #endif @@ -2942,20 +3046,6 @@ static void acpi_register_spi_devices(struct spi_controller *ctlr) static inline void acpi_register_spi_devices(struct spi_controller *ctlr) {} #endif /* CONFIG_ACPI */ -static void spi_controller_release(struct device *dev) -{ - struct spi_controller *ctlr; - - ctlr = container_of(dev, struct spi_controller, dev); - kfree(ctlr); -} - -static struct class spi_master_class = { - .name = "spi_master", - .dev_release = spi_controller_release, - .dev_groups = spi_master_groups, -}; - #ifdef CONFIG_SPI_SLAVE /** * spi_slave_abort - abort the ongoing transfer request on an SPI slave @@ -2983,79 +3073,6 @@ int spi_target_abort(struct spi_device *spi) return -ENOTSUPP; } EXPORT_SYMBOL_GPL(spi_target_abort); - -static ssize_t slave_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct spi_controller *ctlr = container_of(dev, struct spi_controller, - dev); - struct device *child; - - child = device_find_any_child(&ctlr->dev); - return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL); -} - -static ssize_t slave_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct spi_controller *ctlr = container_of(dev, struct spi_controller, - dev); - struct spi_device *spi; - struct device *child; - char name[32]; - int rc; - - rc = sscanf(buf, "%31s", name); - if (rc != 1 || !name[0]) - return -EINVAL; - - child = device_find_any_child(&ctlr->dev); - if (child) { - /* Remove registered slave */ - device_unregister(child); - put_device(child); - } - - if (strcmp(name, "(null)")) { - /* Register new slave */ - spi = spi_alloc_device(ctlr); - if (!spi) - return -ENOMEM; - - strscpy(spi->modalias, name, sizeof(spi->modalias)); - - rc = spi_add_device(spi); - if (rc) { - spi_dev_put(spi); - return rc; - } - } - - return count; -} - -static DEVICE_ATTR_RW(slave); - -static struct attribute *spi_slave_attrs[] = { - &dev_attr_slave.attr, - NULL, -}; - -static const struct attribute_group spi_slave_group = { - .attrs = spi_slave_attrs, -}; - -static const struct attribute_group *spi_slave_groups[] = { - &spi_controller_statistics_group, - &spi_slave_group, - NULL, -}; - -static struct class spi_slave_class = { - .name = "spi_slave", - .dev_release = spi_controller_release, - .dev_groups = spi_slave_groups, -}; #else extern struct class spi_slave_class; /* dummy */ #endif @@ -4749,21 +4766,6 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node) return dev ? to_spi_device(dev) : NULL; } -/* The spi controllers are not using spi_bus, so we find it with another way */ -static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) -{ - struct device *dev; - - dev = class_find_device_by_of_node(&spi_master_class, node); - if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) - dev = class_find_device_by_of_node(&spi_slave_class, node); - if (!dev) - return NULL; - - /* Reference got in class_find_device */ - return container_of(dev, struct spi_controller, dev); -} - static int of_spi_notify(struct notifier_block *nb, unsigned long action, void *arg) { diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index e400d454b3f0..f6fb7bad9a90 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1684,4 +1684,8 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer) return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers); } +#if IS_ENABLED(CONFIG_OF) +struct spi_controller *of_find_spi_controller_by_node(struct device_node *node); +#endif + #endif /* __LINUX_SPI_H */ From patchwork Sun Mar 17 19:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13594828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A809BC54E60 for ; Sun, 17 Mar 2024 19:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W9kltcFJlOvl5Eiz1zCEL33OwRjygg9ksP7fTVIIcB8=; b=n8zNX5d7uMDst/ AY62ydYJ0wQBtwoCa7KAn+VJWH7zyWH0TZDZNFzPdhFulX7gjp2I7FmOFTJkc/oP5RxTUfX5y2DcG HWwgxK42nHn6fqrhFkUteV6ErQubawKZ7Zwk5Rjt8DaPlmYiw4+itKY2z+5UszenT2ov0BPoEHOqE wg+JV2e0tySm6Isdl7F+V26Aw7kUk/0tR/j9Hq5xSyJTBbcgCAhP+mAo3JLGc09jzsJ8D32K+/7LH 6M3NrXkbhJcPJJ0WmwG2YSTJAnGr+N/zVBgyltdxjMVu6GplD7s7khQV9IT1/mgqIiQ03VFN+bJXt sVoJpIn/nagO0xn69yag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwL3-00000006E8q-34G8; Sun, 17 Mar 2024 19:38:34 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwKy-00000006E5W-0iGo for linux-arm-kernel@lists.infradead.org; Sun, 17 Mar 2024 19:38:30 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e7224cb3f2so219469b3a.1 for ; Sun, 17 Mar 2024 12:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704307; x=1711309107; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vO9G69iyqVQbbyIAUNqe8gLJ4ujwClNwkyBvzcpz7K4=; b=dA2Q0zNXz1867vcyBHLMpo4dgnHEY3NniJh4ilL04FLW+DGxwTfIxFQ9Mhx1S0DP+8 GrIjkYIuIeWXU2+Eh8EDFUhiKOfbCh5t2TAOU61rrAZ7h6VGu+wfBrb1BE7/0zPptaOr bcADD68LteDeUUImUsNYZtg3VwBTjmxh7dggLdn8vvjfjZ40qkyMjoKlCCG3w3bk9tQg mj1UPzv+nodr18lR9GpT0ttkxN+vbZEa5tCC+RGQL611wy1EmxsHcZv5dtMYpyN++Ui1 S4AqwXaYODWFvjzULfJ4Tb7FUG5itUC/IhHpGvSEcJAZJQAPKm7ad+au2BdceWPi4A42 KihA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710704307; x=1711309107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vO9G69iyqVQbbyIAUNqe8gLJ4ujwClNwkyBvzcpz7K4=; b=Fd99q62J67dd6JSrxqxK/j9TGQXkDHu8w2QXUyNdeCe0K2aOm6Y/tVHfrQ0DRdLA5p Y+Q8JLfqgkQ7kLqRNUSn5Aer6sgxsFQXAK1L6sI0VIrEdvsEY04o3MwS5BtEuG990lgX J1qNxZAn3zTORnekhBi8Y2PUYDqvThvXF/uoXIqnKVTZh9XtXNt381E8KIsVWaQXOwIQ mLYhRl70iKvzqQRDmJ7UF0gASc8UKYHAuG/BdqrTGs0H/BN5drpCYIihgLasxsB7DIlb 2KPne1v/XcEzymQDTzPsywSg8t35TsLWE/b8zw78e3FGadmFvUBBiJPs2UFVLxRp/VxZ dJJQ== X-Forwarded-Encrypted: i=1; AJvYcCU2JYOeBh7JVQf2ftnCeeHmbmmryp/BXgKr7jrpnoNwydK21SmRXOoXCCvGYbTzbmS40VHrheZd2iFtiTRA3Eq508O0ZmIPHMC63DmV0iCkFkKBAiY= X-Gm-Message-State: AOJu0YyP9POAPnFy8t8hQI64qOqgorFouYSkCtRnOyamU1LEpWDt+6Zm 5UZX72Pp+9Gj251NEMLi5HvP4YiI1iDWwoUSZaBlvzAm86opVeE9 X-Google-Smtp-Source: AGHT+IHb5ZQG5AZs1yNwiaA+uHOH5JqdctbG/pUZFDyCNz6pl0xo2W10sE+uFQzu766SlSdKr8rJ2g== X-Received: by 2002:a17:90a:de93:b0:29d:fb99:7dcc with SMTP id n19-20020a17090ade9300b0029dfb997dccmr9795831pjv.18.1710704306906; Sun, 17 Mar 2024 12:38:26 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id st6-20020a17090b1fc600b0029bbdc920besm6125995pjb.44.2024.03.17.12.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 12:38:26 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org (open list) Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, lorforlinux@beagleboard.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Vaishnav M A , Mark Brown , Johan Hovold , Alex Elder , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS INSTRUMENTS K3 ARCHITECTURE), linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM), Vaishnav M A Subject: [PATCH v4 3/5] greybus: Add mikroBUS manifest types Date: Mon, 18 Mar 2024 01:07:11 +0530 Message-ID: <20240317193714.403132-4-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com> References: <20240317193714.403132-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_123828_373580_83AABE76 X-CRM114-Status: GOOD ( 21.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DONOTMERGE mikroBUS addon boards allow using same mikroBUS connector for a wide range of peripherals. It is also possible for the addon board not to use all the pins in mikroBUS socket (marked by NC or Not Connected). This would require the need to create an almost new overlays for each permutation of the hardware. To overcome this, a manifest format based on Greybus manifest specification was created which allows describing mikroBUS addon boards. The reason for choosing greybus manifest for the identifier is that so far we discussed only about physical mikroBUS ports on the board, but we can also have mikroBUS ports on a remote microcontroller appearing on host over greybus and there a device tree overlay solution does not work as the standard identifier mechanism. The patch introduces 3 new greybus descriptor types: 1. mikrobus-descriptor: Is a fixed-length descriptor (12 bytes), and the manifest shall have precisely one mikroBUS descriptor. Each byte describes a configuration of the corresponding pin on the mikroBUS addon board in a clockwise direction starting from the PWM pin omitting power (VCC and ground) pins as same as the default state of the pin. There are mikroBUS addon boards that use some dedicated SPI, UART, PWM, and I2C pins as GPIO pins, so it is necessary to redefine the default pin configuration of that pins on the host system. Also, sometimes it is required the pull-up on the host pin for correct functionality 2. property-descriptor: Are used to pass named properties or named GPIOs to the host. The host system uses this information to properly configure specific board drivers by passing the properties and GPIO name. There can be multiple instances of property descriptors per add-on board manifest. 3. device-descriptor: Describes a device on the mikroBUS port. The device descriptor is a fixed-length descriptor, and there can be multiple instances of device descriptors in an add-on board manifest in cases where the add-on board presents more than one device to the host. New mikroBUS addon boards also sometimes contain a 1-wire EEPROM with the mikroBUS manifest, thus enabling plug and play support. I have also created PR to add mikrobus descriptors in Greybus spec and I think the old PR on manifesto by Vaishnav should also work. However, both of these repositories seem to be inactive. I am guessing the greybus mailing list can provide more information on how I should go about these. Here is a sample mikroBUS manifest: ``` ;; ; PRESSURE CLICK ; https://www.mikroe.com/pressure-click ; CONFIG_IIO_ST_PRESS ; ; Copyright 2020 BeagleBoard.org Foundation ; Copyright 2020 Texas Instruments ; [manifest-header] version-major = 0 version-minor = 1 [interface-descriptor] vendor-string-id = 1 product-string-id = 2 [string-descriptor 1] string = MIKROE [string-descriptor 2] string = Pressure [mikrobus-descriptor] pwm-state = 4 int-state = 1 rx-state = 7 tx-state = 7 scl-state = 6 sda-state = 6 mosi-state = 5 miso-state = 5 sck-state = 5 cs-state = 5 rst-state = 2 an-state = 1 [device-descriptor 1] driver-string-id = 3 protocol = 0x3 reg = 0x5d [string-descriptor 3] string = lps331ap ``` Link: https://www.mikroe.com/clickid ClickID Link: https://docs.beagleboard.org/latest/projects/beagleconnect/index.html beagleconnect Link: https://github.com/projectara/greybus-spec Greybus Spec Link: https://github.com/projectara/greybus-spec/pull/4 Greybus Spec PR Link: https://github.com/projectara/manifesto/pull/2 manifesto PR Co-developed-by: Vaishnav M A Signed-off-by: Vaishnav M A Signed-off-by: Ayush Singh --- include/linux/greybus/greybus_manifest.h | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/linux/greybus/greybus_manifest.h b/include/linux/greybus/greybus_manifest.h index bef9eb2093e9..83241e19d9b3 100644 --- a/include/linux/greybus/greybus_manifest.h +++ b/include/linux/greybus/greybus_manifest.h @@ -23,6 +23,9 @@ enum greybus_descriptor_type { GREYBUS_TYPE_STRING = 0x02, GREYBUS_TYPE_BUNDLE = 0x03, GREYBUS_TYPE_CPORT = 0x04, + GREYBUS_TYPE_MIKROBUS = 0x05, + GREYBUS_TYPE_PROPERTY = 0x06, + GREYBUS_TYPE_DEVICE = 0x07, }; enum greybus_protocol { @@ -151,6 +154,49 @@ struct greybus_descriptor_cport { __u8 protocol_id; /* enum greybus_protocol */ } __packed; +/* + * A mikrobus descriptor is used to describe the details + * about the bus ocnfiguration for the add-on board + * connected to the mikrobus port. + */ +struct greybus_descriptor_mikrobus { + __u8 pin_state[12]; +} __packed; + +/* + * A property descriptor is used to pass named properties + * to device drivers through the unified device properties + * interface under linux/property.h + */ +struct greybus_descriptor_property { + __u8 length; + __u8 id; + __u8 propname_stringid; + __u8 type; + __u8 value[]; +} __packed; + +/* + * A device descriptor is used to describe the + * details required by a add-on board device + * driver. + */ +struct greybus_descriptor_device { + __u8 id; + __u8 driver_stringid; + __u8 protocol; + __u8 reg; + __le32 max_speed_hz; + __u8 irq; + __u8 irq_type; + __u8 mode; + __u8 prop_link; + __u8 gpio_link; + __u8 reg_link; + __u8 clock_link; + __u8 pad[1]; +} __packed; + struct greybus_descriptor_header { __le16 size; __u8 type; /* enum greybus_descriptor_type */ @@ -164,6 +210,9 @@ struct greybus_descriptor { struct greybus_descriptor_interface interface; struct greybus_descriptor_bundle bundle; struct greybus_descriptor_cport cport; + struct greybus_descriptor_mikrobus mikrobus; + struct greybus_descriptor_property property; + struct greybus_descriptor_device device; }; } __packed; From patchwork Sun Mar 17 19:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13594829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 124F0C54E67 for ; Sun, 17 Mar 2024 19:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Jt2GnBapqmjIKB5liwi45vFgyOHpBq2sx1esphx8Y1g=; b=mjYW33vdAUoV4D CJ9sPLgeWXHqVYnwBLU8lXbrbePRu+6wTxmCKCLjRySR6O+jdMsPSNrXIp+jfCm9cwgv/UCNs0mSO +hcq4Zpi11OWwVy/pyHrzEVBzIVMdSiH70Kuy0T9HpN91NV5FGDPTq6Oulei1dR0ukxRO4kYohf78 +Y4AbZEt5nr3QbDsKURL42GtkbCGeoiv860AYspylyKFPY2KdHfCgRUiQBDkX0UKMZs984hyBBgba dTWCUM28OkhNdGfA1Kuu+Hbzv+tWoq4VqPINtmTijlcFYikcjiKF/Q/iwpzsyWYFdE8hciIwkfuen JuNB9tMko7YV6cwaSCZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwLF-00000006EFn-3lIY; Sun, 17 Mar 2024 19:38:46 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwL7-00000006EAO-1SJR for linux-arm-kernel@lists.infradead.org; Sun, 17 Mar 2024 19:38:43 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6e125818649so1419205a34.1 for ; Sun, 17 Mar 2024 12:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704316; x=1711309116; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JIjZbYAaC7Szl64I9+yOIL6zkvga0zthWgnNY93d+E4=; b=GZOmpgYcLqDUV9skY1YjKXKNkqL2QiRU2C3Zv07SRVSvJlgEbMuCd6jrfo9EeOsMNm GYVMTjjoCb1sYl/8KZ5JlZBeXHafW5BQi1lX1Gw3QdRUiKZidCDD3HFPk7IstFSq4DHA +za16aNuHPr77Ueq3UCy04cfiizkZNzQwlAJ9kJDVX4txVoesKlrrDihkz4aV1OUlST0 9ebXcgQXOrGa7Es4JoEtk1Y04eMzly5Bvu9wLzrOD84og6F9199xDW8t5eF1f+fiYaLs EK0uPXgXL/i//jJpuztQj5wiAckifiOPGBSMVZH8Al7afJcpXQyVgusKagCh1BCrxJOF qtPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710704316; x=1711309116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JIjZbYAaC7Szl64I9+yOIL6zkvga0zthWgnNY93d+E4=; b=nc5uqf8Wf7nx6QUh+HgAudzZyxcT/fPC7cVa4wowTM57MN31JiY1QXcYfEmwDuzllI TLcR0FlYdc4i14xka35AcY/+L7nNJB6GPZKRo9ke0ONN3o5BLAo2WvJ9Z1QW+ZEd3BCD duKfxXNqjH+TNyah0hCW3cIssUhvFS5IOfwlrfC5MnbUHDtlLGEwWhHLmDjUBaBXWf88 BeFR+k2P+x2+eFXmenrzrvM2NRhy35d8GHc4HBpRkoTO9TjaN+LcBxTA8kdLPCjYmxV/ 76IVZw29W4JG2TefVTbMBvm0jpCrtDbHeYykrmjR+AmHsThi+3nv782TtTuo/1DFiacu rLNA== X-Forwarded-Encrypted: i=1; AJvYcCW7QlPlnFmaBdGrNQd0nf5T1rrJFCrS8h8HrM8eFdni2oxGYLx9tkedhrlkW3lzdD8SZyNnitmM0DyBIc3AKeWh566vhWSZTyU4zWPz8ObZQ3s/uek= X-Gm-Message-State: AOJu0YyCpivvU4moocIwiN1vLFEiz4SfF4BZ4+Gm7YR6sbvPuJWXmB8s 8gA+RGVROH5H/OA9X99IM/h+EMjhBeCAVrxOiUrSacgH3v2EOQ8X X-Google-Smtp-Source: AGHT+IE2ShYpKMdMbrRjB8C0x2MiX9wzjENIjU3Z/Sg7Mgzto4T5JKCuVzFq+s5AReUmk2BJ3DJ13A== X-Received: by 2002:a05:6358:59a2:b0:17b:6171:adaa with SMTP id c34-20020a05635859a200b0017b6171adaamr8729146rwf.20.1710704315465; Sun, 17 Mar 2024 12:38:35 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id st6-20020a17090b1fc600b0029bbdc920besm6125995pjb.44.2024.03.17.12.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 12:38:34 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org (open list) Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, lorforlinux@beagleboard.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Vaishnav M A , Mark Brown , Johan Hovold , Alex Elder , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS INSTRUMENTS K3 ARCHITECTURE), linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM), Vaishnav M A Subject: [PATCH v4 4/5] mikrobus: Add mikroBUS driver Date: Mon, 18 Mar 2024 01:07:12 +0530 Message-ID: <20240317193714.403132-5-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com> References: <20240317193714.403132-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_123838_120739_9AD26325 X-CRM114-Status: GOOD ( 29.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DONOTMERGE this patch depends on Patch 1, 2, 3 mikroBUS driver aims to split the platform aspects of mikroBUS (pinmux, SPI/I2C/GPIO controller .etc) from the add-on board information, thus requiring one device tree overlay per port and just a single manifest describing the add-on board. The driver exposes a sysfs entry that allows passing mikroBUS manifest of add-on board to the driver. The driver then parses this manifest, sets up the pins and protocols and allows using the appropriate Linux driver. Here is an example: ``` cat /lib/firmware/mikrobus/AMBIENT-2-CLICK.mnfb > /sys/bus/mikrobus/devices/mikrobus-0/new_device ``` Another sysfs entry is exposed that allows removing a previously registered mikrobus add-on board: ``` echo " " > /sys/bus/mikrobus/devices/mikrobus-0/delete_device ``` 100s of mikroBUS addon board manifests can be found in the clickID repository. In the future the driver also aims to support plug and play support using 1-wire EEPROM and mikroBUS over greybus. Link: https://www.mikroe.com/clickid ClickID Co-developed-by: Vaishnav M A Signed-off-by: Vaishnav M A Signed-off-by: Ayush Singh --- MAINTAINERS | 1 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/mikrobus/Kconfig | 15 + drivers/misc/mikrobus/Makefile | 5 + drivers/misc/mikrobus/mikrobus_core.c | 696 ++++++++++++++++++++++ drivers/misc/mikrobus/mikrobus_core.h | 151 +++++ drivers/misc/mikrobus/mikrobus_manifest.c | 503 ++++++++++++++++ drivers/misc/mikrobus/mikrobus_manifest.h | 29 + 9 files changed, 1402 insertions(+) create mode 100644 drivers/misc/mikrobus/Kconfig create mode 100644 drivers/misc/mikrobus/Makefile create mode 100644 drivers/misc/mikrobus/mikrobus_core.c create mode 100644 drivers/misc/mikrobus/mikrobus_core.h create mode 100644 drivers/misc/mikrobus/mikrobus_manifest.c create mode 100644 drivers/misc/mikrobus/mikrobus_manifest.h diff --git a/MAINTAINERS b/MAINTAINERS index 69418a058c6b..83bc5e48bef9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14772,6 +14772,7 @@ M: Ayush Singh M: Vaishnav M A S: Maintained F: Documentation/devicetree/bindings/misc/mikrobus-connector.yaml +F: drivers/misc/mikrobus/* MIKROTIK CRS3XX 98DX3236 BOARD SUPPORT M: Luka Kovacic diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 4fb291f0bf7c..3d5c36205c6c 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -591,4 +591,5 @@ source "drivers/misc/cardreader/Kconfig" source "drivers/misc/uacce/Kconfig" source "drivers/misc/pvpanic/Kconfig" source "drivers/misc/mchp_pci1xxxx/Kconfig" +source "drivers/misc/mikrobus/Kconfig" endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index ea6ea5bbbc9c..b9ac88055b87 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -68,3 +68,4 @@ obj-$(CONFIG_TMR_INJECT) += xilinx_tmr_inject.o obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o +obj-y += mikrobus/ diff --git a/drivers/misc/mikrobus/Kconfig b/drivers/misc/mikrobus/Kconfig new file mode 100644 index 000000000000..aa57b994dc66 --- /dev/null +++ b/drivers/misc/mikrobus/Kconfig @@ -0,0 +1,15 @@ +menuconfig MIKROBUS + tristate "Module for instantiating devices on mikroBUS ports" + depends on GPIOLIB + help + This option enables the mikroBUS driver. mikroBUS is an add-on + board socket standard that offers maximum expandability with + the smallest number of pins. The mikroBUS driver instantiates + devices on a mikroBUS port described mikroBUS manifest which is + passed using a sysfs interface. + + + Say Y here to enable support for this driver. + + To compile this code as a module, chose M here: the module + will be called mikrobus.ko diff --git a/drivers/misc/mikrobus/Makefile b/drivers/misc/mikrobus/Makefile new file mode 100644 index 000000000000..0e51c5a7db4b --- /dev/null +++ b/drivers/misc/mikrobus/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# mikroBUS Core + +obj-$(CONFIG_MIKROBUS) += mikrobus.o +mikrobus-y := mikrobus_core.o mikrobus_manifest.o diff --git a/drivers/misc/mikrobus/mikrobus_core.c b/drivers/misc/mikrobus/mikrobus_core.c new file mode 100644 index 000000000000..6aa20cef8e3b --- /dev/null +++ b/drivers/misc/mikrobus/mikrobus_core.c @@ -0,0 +1,696 @@ +// SPDX-License-Identifier: GPL-2.0: +/* + * mikroBUS driver for instantiating add-on + * board devices with an identifier EEPROM + * + * Copyright 2020 Vaishnav M A, BeagleBoard.org Foundation. + * Copyright 2024 Ayush Singh + */ + +#define pr_fmt(fmt) "mikrobus:%s: " fmt, __func__ + +#include "linux/gpio/driver.h" +#include "linux/gpio/machine.h" +#include "linux/gpio/consumer.h" +#include "linux/greybus/greybus_manifest.h" +#include "linux/i2c.h" +#include "linux/irq.h" +#include "linux/pinctrl/consumer.h" +#include "linux/platform_device.h" +#include "linux/spi/spi.h" + +#include "mikrobus_core.h" +#include "mikrobus_manifest.h" + +static struct class_compat *mikrobus_port_compat_class; + +static const struct bus_type mikrobus_bus_type = { + .name = "mikrobus", +}; + +static int mikrobus_board_register(struct mikrobus_port *port, + struct addon_board_info *board); +static void mikrobus_board_unregister(struct mikrobus_port *port, + struct addon_board_info *board); + +/* + * mikrobus_pinctrl_select: Select pinctrl state for mikrobus pin + * + * @port: mikrobus port + * @pinctrl_selected: pinctrl state to be selected + */ +static int mikrobus_pinctrl_select(struct mikrobus_port *port, + const char *pinctrl_selected) +{ + struct pinctrl_state *state; + int ret; + + state = pinctrl_lookup_state(port->pinctrl, pinctrl_selected); + if (IS_ERR(state)) { + return dev_err_probe(&port->dev, PTR_ERR(state), + "failed to find state %s", + pinctrl_selected); + } + + ret = pinctrl_select_state(port->pinctrl, state); + if (ret) { + return dev_err_probe(&port->dev, ret, + "failed to select state %s", + pinctrl_selected); + } + dev_dbg(&port->dev, "setting pinctrl %s", pinctrl_selected); + + return 0; +} + +/* + * mikrobus_pinctrl_setup: Setup mikrobus pins to either default of gpio + * + * @port: mikrobus port + * @board: mikrobus board or NULL for default state + * + * returns 0 on success, negative error code on failure + */ +static int mikrobus_pinctrl_setup(struct mikrobus_port *port, + struct addon_board_info *board) +{ + int ret; + + if (!board || board->pin_state[MIKROBUS_PIN_PWM] == MIKROBUS_STATE_PWM) + ret = mikrobus_pinctrl_select(port, "pwm_default"); + else + ret = mikrobus_pinctrl_select(port, "pwm_gpio"); + if (ret) + return ret; + + if (!board || board->pin_state[MIKROBUS_PIN_RX] == MIKROBUS_STATE_UART) + ret = mikrobus_pinctrl_select(port, "uart_default"); + else + ret = mikrobus_pinctrl_select(port, "uart_gpio"); + if (ret) + return ret; + + if (!board || board->pin_state[MIKROBUS_PIN_SCL] == MIKROBUS_STATE_I2C) + ret = mikrobus_pinctrl_select(port, "i2c_default"); + else + ret = mikrobus_pinctrl_select(port, "i2c_gpio"); + if (ret) + return ret; + + if (!board || board->pin_state[MIKROBUS_PIN_MOSI] == MIKROBUS_STATE_SPI) + ret = mikrobus_pinctrl_select(port, "spi_default"); + else + ret = mikrobus_pinctrl_select(port, "spi_gpio"); + + return ret; +} + +/* + * new_device_store: Expose sysfs entry for adding new board + * + * new_device_store: Allows userspace to add mikroBUS boards that lack 1-wire + * EEPROM for board identification by manually passing mikroBUS manifest + */ +static ssize_t new_device_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct mikrobus_port *port = to_mikrobus_port(dev); + struct addon_board_info *board; + int ret; + + if (port->board) + return dev_err_probe(dev, -EBUSY, + "already has board registered"); + + board = devm_kzalloc(&port->dev, sizeof(*board), GFP_KERNEL); + if (!board) + return -ENOMEM; + + INIT_LIST_HEAD(&board->manifest_descs); + INIT_LIST_HEAD(&board->devices); + + ret = mikrobus_manifest_parse(board, (void *)buf, count); + if (ret < 0) { + ret = dev_err_probe(dev, -EINVAL, "failed to parse manifest"); + goto err_free_board; + } + + ret = mikrobus_board_register(port, board); + if (ret) { + ret = dev_err_probe(dev, -EINVAL, "failed to register board %s", + board->name); + goto err_free_board; + } + + return count; + +err_free_board: + devm_kfree(&port->dev, board); + return ret; +} +static DEVICE_ATTR_WO(new_device); + +/* + * delete_device_store: Expose sysfs entry for deleting board + */ +static ssize_t delete_device_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mikrobus_port *port = to_mikrobus_port(dev); + + if (!port->board) + return dev_err_probe(dev, -ENODEV, + "does not have registered boards"); + + mikrobus_board_unregister(port, port->board); + return count; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + delete_device_store); + +static struct attribute *mikrobus_port_attrs[] = { &dev_attr_new_device.attr, + &dev_attr_delete_device.attr, + NULL }; +ATTRIBUTE_GROUPS(mikrobus_port); + +static void mikrobus_port_release(struct device *dev) +{ +} + +static const struct device_type mikrobus_port_type = { + .groups = mikrobus_port_groups, + .release = mikrobus_port_release, +}; + +static int mikrobus_irq_get(struct mikrobus_port *port, int irqno, int irq_type) +{ + int irq; + + if (irqno > port->gpios->ndescs - 1) + return dev_err_probe(&port->dev, -ENODEV, + "GPIO %d does not exist", irqno); + + irq = gpiod_to_irq(port->gpios->desc[irqno]); + if (irq < 0) + return dev_err_probe(&port->dev, -EINVAL, + "could not get irq %d", irqno); + + irq_set_irq_type(irq, irq_type); + + return irq; +} + +static int mikrobus_gpio_setup(struct gpio_desc *gpio, int gpio_state) +{ + switch (gpio_state) { + case MIKROBUS_STATE_INPUT: + return gpiod_direction_input(gpio); + case MIKROBUS_STATE_OUTPUT_HIGH: + return gpiod_direction_output(gpio, 1); + case MIKROBUS_STATE_OUTPUT_LOW: + return gpiod_direction_output(gpio, 0); + case MIKROBUS_STATE_PWM: + case MIKROBUS_STATE_SPI: + case MIKROBUS_STATE_I2C: + default: + return 0; + } +} + +static char *mikrobus_gpio_chip_name_get(struct mikrobus_port *port, int gpio) +{ + struct gpio_chip *gpiochip; + + if (gpio > port->gpios->ndescs - 1) + return NULL; + + gpiochip = gpiod_to_chip(port->gpios->desc[gpio]); + return kmemdup(gpiochip->label, strlen(gpiochip->label), GFP_KERNEL); +} + +static int mikrobus_gpio_hwnum_get(struct mikrobus_port *port, int gpio) +{ + struct gpio_chip *gpiochip; + + if (gpio > port->gpios->ndescs - 1) + return -ENODEV; + + gpiochip = gpiod_to_chip(port->gpios->desc[gpio]); + return desc_to_gpio(port->gpios->desc[gpio]) - gpiochip->base; +} + +static void mikrobus_board_device_release_all(struct addon_board_info *info) +{ + struct board_device_info *dev, *next; + + list_for_each_entry_safe(dev, next, &info->devices, links) { + list_del(&dev->links); + kfree(dev); + } +} + +static int mikrobus_device_register(struct mikrobus_port *port, + struct board_device_info *dev, + char *board_name) +{ + struct gpiod_lookup_table *lookup; + struct spi_board_info *spi_info; + struct i2c_board_info *i2c_info; + struct platform_device *pdev; + struct fwnode_handle *fwnode; + struct spi_device *spi; + struct i2c_client *i2c; + int i, ret; + + dev_info(&port->dev, "registering device : %s", dev->drv_name); + + if (dev->gpio_lookup) { + lookup = dev->gpio_lookup; + + switch (dev->protocol) { + case GREYBUS_PROTOCOL_SPI: + lookup->dev_id = kasprintf(GFP_KERNEL, "%s.%u", + dev->drv_name, + port->chip_select[dev->reg]); + break; + case GREYBUS_PROTOCOL_RAW: + lookup->dev_id = kasprintf(GFP_KERNEL, "%s.%u", + dev->drv_name, dev->reg); + break; + default: + lookup->dev_id = kmemdup(dev->drv_name, + strlen(dev->drv_name), + GFP_KERNEL); + } + + dev_info(&port->dev, "adding lookup table : %s", + lookup->dev_id); + + for (i = 0; i < dev->num_gpio_resources; i++) { + lookup->table[i].key = mikrobus_gpio_chip_name_get( + port, lookup->table[i].chip_hwnum); + lookup->table[i].chip_hwnum = mikrobus_gpio_hwnum_get( + port, lookup->table[i].chip_hwnum); + } + + gpiod_add_lookup_table(lookup); + } + + switch (dev->protocol) { + case GREYBUS_PROTOCOL_SPI: + spi_info = + devm_kzalloc(&port->dev, sizeof(*spi_info), GFP_KERNEL); + strscpy_pad(spi_info->modalias, dev->drv_name, + sizeof(spi_info->modalias)); + if (dev->irq) + spi_info->irq = + mikrobus_irq_get(port, dev->irq, dev->irq_type); + if (dev->properties) { + fwnode = fwnode_create_software_node(dev->properties, + NULL); + spi_info->swnode = to_software_node(fwnode); + } + spi_info->chip_select = port->chip_select[dev->reg]; + spi_info->max_speed_hz = dev->max_speed_hz; + spi_info->mode = dev->mode; + + spi = spi_new_device(port->spi_ctrl, spi_info); + devm_kfree(&port->dev, spi_info); + if (!spi) + return dev_err_probe(&port->dev, -ENODEV, + "failed to register spi device"); + dev->dev_client = (void *)spi; + break; + case GREYBUS_PROTOCOL_I2C: + i2c_info = + devm_kzalloc(&port->dev, sizeof(*i2c_info), GFP_KERNEL); + if (!i2c_info) + return -ENOMEM; + + strscpy_pad(i2c_info->type, dev->drv_name, + sizeof(i2c_info->type)); + if (dev->irq) + i2c_info->irq = + mikrobus_irq_get(port, dev->irq, dev->irq_type); + if (dev->properties) { + fwnode = fwnode_create_software_node(dev->properties, + NULL); + i2c_info->swnode = to_software_node(fwnode); + } + i2c_info->addr = dev->reg; + + i2c = i2c_new_client_device(port->i2c_adap, i2c_info); + devm_kfree(&port->dev, i2c_info); + if (IS_ERR(dev->dev_client)) + return dev_err_probe(&port->dev, + PTR_ERR(dev->dev_client), + "failed to register i2c device"); + dev->dev_client = (void *)i2c; + break; + case GREYBUS_PROTOCOL_RAW: + pdev = platform_device_alloc(dev->drv_name, 0); + if (!pdev) + return -ENOMEM; + + if (dev->properties) { + ret = device_create_managed_software_node( + &pdev->dev, dev->properties, NULL); + if (ret) + return dev_err_probe( + &port->dev, ret, + "failed to create software node"); + } + ret = platform_device_add(dev->dev_client); + if (ret) + return dev_err_probe( + &port->dev, ret, + "failed to register platform device"); + dev->dev_client = (void *)pdev; + break; + case GREYBUS_PROTOCOL_UART: + default: + return -EINVAL; + } + + return 0; +} + +static void mikrobus_device_unregister(struct mikrobus_port *port, + struct board_device_info *dev, + char *board_name) +{ + dev_info(&port->dev, "removing device %s", dev->drv_name); + if (dev->gpio_lookup) { + gpiod_remove_lookup_table(dev->gpio_lookup); + kfree(dev->gpio_lookup->dev_id); + kfree(dev->gpio_lookup); + } + + kfree(dev->properties); + + switch (dev->protocol) { + case GREYBUS_PROTOCOL_SPI: + spi_unregister_device((struct spi_device *)dev->dev_client); + break; + case GREYBUS_PROTOCOL_I2C: + i2c_unregister_device((struct i2c_client *)dev->dev_client); + break; + case GREYBUS_PROTOCOL_RAW: + platform_device_unregister( + (struct platform_device *)dev->dev_client); + break; + case GREYBUS_PROTOCOL_UART: + break; + } +} + +static int mikrobus_board_register(struct mikrobus_port *port, + struct addon_board_info *board) +{ + struct board_device_info *devinfo, *next; + int ret, i; + + if (WARN_ON(list_empty(&board->devices))) + return false; + + if (port->pinctrl) { + ret = mikrobus_pinctrl_setup(port, board); + if (ret) + dev_err(&port->dev, + "failed to setup pinctrl state [%d]", ret); + } + + if (port->gpios) { + for (i = 0; i < port->gpios->ndescs; i++) { + ret = mikrobus_gpio_setup(port->gpios->desc[i], + board->pin_state[i]); + if (ret) + dev_err(&port->dev, + "failed to setup gpio %d, state %d", i, + board->pin_state[i]); + + gpiochip_free_own_desc(port->gpios->desc[i]); + } + } + + list_for_each_entry_safe(devinfo, next, &board->devices, links) + mikrobus_device_register(port, devinfo, board->name); + + port->board = board; + return 0; +} + +static void mikrobus_board_unregister(struct mikrobus_port *port, + struct addon_board_info *board) +{ + struct board_device_info *devinfo, *next; + + if (WARN_ON(list_empty(&board->devices))) + return; + + list_for_each_entry_safe(devinfo, next, &board->devices, links) + mikrobus_device_unregister(port, devinfo, board->name); + + mikrobus_board_device_release_all(board); + devm_kfree(&port->dev, board); + port->board = NULL; +} + +static int mikrobus_port_register(struct mikrobus_port *port) +{ + int ret; + + port->dev.bus = &mikrobus_bus_type; + port->dev.type = &mikrobus_port_type; + dev_set_name(&port->dev, "mikrobus-%d", port->id); + + dev_info(&port->dev, "registering port %s", dev_name(&port->dev)); + + ret = device_register(&port->dev); + if (ret) + return dev_err_probe(&port->dev, ret, + "port '%d': can't register device (%d)", + port->id, ret); + + ret = class_compat_create_link(mikrobus_port_compat_class, &port->dev, + port->dev.parent); + if (ret) + dev_warn(&port->dev, + "failed to create compatibility class link"); + + return ret; +} + +static void mikrobus_port_delete(struct mikrobus_port *port) +{ + if (port->board) + return dev_err( + &port->dev, + "attempting to delete port with registered boards, port [%s]", + dev_name(&port->dev)); + + class_compat_remove_link(mikrobus_port_compat_class, &port->dev, + port->dev.parent); + + devm_pinctrl_put(port->pinctrl); + put_device(&port->spi_ctrl->dev); + gpiod_put_array(port->gpios); + put_device(&port->i2c_adap->dev); + + device_unregister(&port->dev); + memset(&port->dev, 0, sizeof(port->dev)); +} + +static int mikrobus_port_probe_pinctrl_setup(struct mikrobus_port *port) +{ + struct device *dev = port->dev.parent; + struct pinctrl_state *state; + int ret; + + state = pinctrl_lookup_state(port->pinctrl, PINCTRL_STATE_DEFAULT); + if (IS_ERR(state)) + return dev_err_probe(dev, PTR_ERR(state), + "failed to find state %s", + PINCTRL_STATE_DEFAULT); + + ret = pinctrl_select_state(port->pinctrl, state); + if (ret) + return dev_err_probe(dev, ret, "Failed to select state %s", + PINCTRL_STATE_DEFAULT); + + ret = mikrobus_pinctrl_setup(port, NULL); + if (ret) + dev_err(dev, "failed to select pinctrl states [%d]", ret); + + return ret; +} + +static int mikrobus_port_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct mikrobus_port *port; + struct device_node *np; + int ret; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + port->dev.parent = dev; + port->dev.of_node = pdev->dev.of_node; + + /* port id */ + port->id = of_alias_get_id(dev->of_node, "mikrobus"); + if (port->id) { + ret = dev_err_probe(dev, -EINVAL, "invalid mikrobus id"); + goto err_port; + } + + /* I2C setup */ + np = of_parse_phandle(dev->of_node, "i2c-adapter", 0); + if (!np) { + ret = dev_err_probe(dev, -ENODEV, "cannot parse i2c-adapter"); + goto err_port; + } + port->i2c_adap = of_find_i2c_adapter_by_node(np); + of_node_put(np); + if (!port->i2c_adap) { + ret = dev_err_probe(dev, -ENODEV, "cannot find i2c adapter"); + goto err_port; + } + + /* GPIO setup */ + port->gpios = gpiod_get_array(dev, "mikrobus", GPIOD_OUT_LOW); + if (IS_ERR(port->gpios)) { + ret = dev_err_probe(dev, PTR_ERR(port->gpios), + "failed to get gpio array [%ld]", + PTR_ERR(port->gpios)); + goto free_i2c; + } + + /* SPI setup */ + np = of_parse_phandle(dev->of_node, "spi-controller", 0); + if (!np) { + ret = dev_err_probe(dev, -ENODEV, + "cannot parse spi-controller"); + goto free_gpio; + } + port->spi_ctrl = of_find_spi_controller_by_node(np); + of_node_put(np); + if (!port->spi_ctrl) { + ret = dev_err_probe(dev, -ENODEV, "cannot find spi controller"); + goto free_gpio; + } + ret = device_property_read_u32_array(dev, "spi-cs", port->chip_select, + MIKROBUS_NUM_CS); + if (ret) { + dev_err(dev, "failed to get spi-cs [%d]", ret); + goto free_spi; + } + + /* pinctrl setup */ + port->pinctrl = devm_pinctrl_get(dev); + if (IS_ERR(port->pinctrl)) { + ret = dev_err_probe(dev, PTR_ERR(port->pinctrl), + "failed to get pinctrl [%ld]", + PTR_ERR(port->pinctrl)); + goto free_spi; + } + ret = mikrobus_port_probe_pinctrl_setup(port); + if (ret) { + dev_err(dev, "failed to setup pinctrl [%d]", ret); + goto free_pinctrl; + } + + /* TODO: UART */ + /* TODO: PWM */ + + ret = mikrobus_port_register(port); + if (ret) { + dev_err(dev, "port : can't register port [%d]", ret); + goto free_pinctrl; + } + + platform_set_drvdata(pdev, port); + + return 0; + +free_pinctrl: + devm_pinctrl_put(port->pinctrl); +free_spi: + put_device(&port->spi_ctrl->dev); +free_gpio: + gpiod_put_array(port->gpios); +free_i2c: + put_device(&port->i2c_adap->dev); +err_port: + put_device(&port->dev); + return ret; +} + +static int mikrobus_port_remove(struct platform_device *pdev) +{ + struct mikrobus_port *port = platform_get_drvdata(pdev); + + mikrobus_port_delete(port); + return 0; +} + +static const struct of_device_id mikrobus_port_of_match[] = { + { .compatible = "mikrobus-connector" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mikrobus_port_of_match); + +static struct platform_driver mikrobus_port_driver = { + .probe = mikrobus_port_probe, + .remove = mikrobus_port_remove, + .driver = { + .name = "mikrobus", + .of_match_table = mikrobus_port_of_match, + }, +}; + +static int mikrobus_init(void) +{ + int ret; + + ret = bus_register(&mikrobus_bus_type); + if (ret) { + pr_err("bus_register failed (%d)", ret); + return ret; + } + + mikrobus_port_compat_class = class_compat_register("mikrobus-port"); + if (!mikrobus_port_compat_class) { + ret = -ENOMEM; + pr_err("class_compat register failed (%d)", ret); + goto class_err; + } + + ret = platform_driver_register(&mikrobus_port_driver); + if (ret) + pr_err("driver register failed [%d]", ret); + + return ret; + +class_err: + bus_unregister(&mikrobus_bus_type); + return ret; +} +subsys_initcall(mikrobus_init); + +static void mikrobus_exit(void) +{ + platform_driver_unregister(&mikrobus_port_driver); + bus_unregister(&mikrobus_bus_type); + class_compat_unregister(mikrobus_port_compat_class); +} +module_exit(mikrobus_exit); + +MODULE_AUTHOR("Vaishnav M A "); +MODULE_AUTHOR("Ayush Singh "); +MODULE_DESCRIPTION("mikroBUS main module"); +MODULE_LICENSE("GPL"); diff --git a/drivers/misc/mikrobus/mikrobus_core.h b/drivers/misc/mikrobus/mikrobus_core.h new file mode 100644 index 000000000000..1d41ee32ca94 --- /dev/null +++ b/drivers/misc/mikrobus/mikrobus_core.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * mikroBUS Driver for instantiating add-on board devices + * + * Copyright 2020 Vaishnav M A, BeagleBoard.org Foundation. + * Copyright 2024 Ayush Singh + */ + +#ifndef __MIKROBUS_H +#define __MIKROBUS_H + +#include "linux/device.h" + +#define MIKROBUS_VERSION_MAJOR 0x00 +#define MIKROBUS_VERSION_MINOR 0x03 + +#define MIKROBUS_NUM_PINCTRL_STATE 4 +#define MIKROBUS_NUM_CS 2 + +#define MIKROBUS_PINCTRL_PWM 0 +#define MIKROBUS_PINCTRL_UART 1 +#define MIKROBUS_PINCTRL_I2C 2 +#define MIKROBUS_PINCTRL_SPI 3 + +enum mikrobus_property_type { + MIKROBUS_PROPERTY_TYPE_MIKROBUS = 0x00, + MIKROBUS_PROPERTY_TYPE_PROPERTY, + MIKROBUS_PROPERTY_TYPE_GPIO, + MIKROBUS_PROPERTY_TYPE_U8, + MIKROBUS_PROPERTY_TYPE_U16, + MIKROBUS_PROPERTY_TYPE_U32, + MIKROBUS_PROPERTY_TYPE_U64, +}; + +enum mikrobus_pin { + MIKROBUS_PIN_PWM = 0x00, + MIKROBUS_PIN_INT, + MIKROBUS_PIN_RX, + MIKROBUS_PIN_TX, + MIKROBUS_PIN_SCL, + MIKROBUS_PIN_SDA, + MIKROBUS_PIN_MOSI, + MIKROBUS_PIN_MISO, + MIKROBUS_PIN_SCK, + MIKROBUS_PIN_CS, + MIKROBUS_PIN_RST, + MIKROBUS_PIN_AN, + MIKROBUS_PORT_PIN_COUNT, +}; + +enum mikrobus_pin_state { + MIKROBUS_STATE_INPUT = 0x01, + MIKROBUS_STATE_OUTPUT_HIGH, + MIKROBUS_STATE_OUTPUT_LOW, + MIKROBUS_STATE_PWM, + MIKROBUS_STATE_SPI, + MIKROBUS_STATE_I2C, + MIKROBUS_STATE_UART, +}; + +/* + * board_device_info describes a single device on a mikrobus add-on + * board, an add-on board can present one or more device to the host + * + * @gpio_lookup: used to provide the GPIO lookup table for + * passing the named GPIOs to device drivers. + * @properties: used to provide the property_entry to pass named + * properties to device drivers, applicable only when driver uses + * device_property_read_* calls to fetch the properties. + * @num_gpio_resources: number of named gpio resources for the device, + * used mainly for gpiod_lookup_table memory allocation. + * @num_properties: number of custom properties for the device, + * used mainly for property_entry memory allocation. + * @protocol: used to know the type of the device and it should + * contain one of the values defined under 'enum greybus_class_type' + * under linux/greybus/greybus_manifest.h + * @reg: I2C address for the device, for devices on the SPI bus + * this field is the chip select address relative to the mikrobus + * port:0->device chip select connected to CS pin on mikroBUS port + * 1->device chip select connected to RST Pin on mikroBUS port + * @mode: SPI mode + * @max_speed_hz: SPI max speed(Hz) + * @drv_name: device_id to match with the driver + * @irq_type: type of IRQ trigger , match with defines in linux/interrupt.h + * @irq: irq number relative to the mikrobus port should contain one of the + * values defined under 'enum mikrobus_pin' + * @id: device id starting from 1 + */ +struct board_device_info { + struct gpiod_lookup_table *gpio_lookup; + struct property_entry *properties; + struct list_head links; + unsigned short num_gpio_resources; + unsigned short num_properties; + unsigned short protocol; + unsigned short reg; + unsigned int mode; + void *dev_client; + u32 max_speed_hz; + char *drv_name; + int irq_type; + int irq; + int id; +}; + +/* + * addon_board_info describes a mikrobus add-on device the add-on + * board, an add-on board can present one or more device to the host + * + * @manifest_descs: list of manifest descriptors + * @devices: list of devices on the board + * @pin_state: the state of each pin on the mikrobus port required + * for the add-on board should contain one of the values defined under + * 'enum mikrobus_pin_state' restrictions are as per mikrobus standard + * specifications. + * @name: add-on board name + */ +struct addon_board_info { + struct list_head manifest_descs; + struct list_head devices; + u8 pin_state[MIKROBUS_PORT_PIN_COUNT]; + char *name; +}; + +/* + * mikrobus_port describes the peripherals mapped to a mikrobus port. + * + * @chip_select: chip select number mapped to the SPI CS pin on the + * mikrobus port and the RST pin on the mikrobus port + * @board: pointer to the attached add-on board. + * @spi_ctrl: SPI controller attached to the mikrobus port. + * @i2c_adap: I2C adapter attached to the mikrobus port. + * @gpios: GPIOs attached to the mikrobus port. + * @pinctrl: pinctrl attached to the mikrobus port. + * @dev: device structure for the mikrobus port. + * @id: port id starting from 1 + */ +struct mikrobus_port { + u32 chip_select[MIKROBUS_NUM_CS]; + struct addon_board_info *board; + struct spi_controller *spi_ctrl; + struct i2c_adapter *i2c_adap; + struct gpio_descs *gpios; + struct pinctrl *pinctrl; + struct device dev; + int id; +}; + +#define to_mikrobus_port(d) container_of(d, struct mikrobus_port, dev) + +#endif /* __MIKROBUS_H */ diff --git a/drivers/misc/mikrobus/mikrobus_manifest.c b/drivers/misc/mikrobus/mikrobus_manifest.c new file mode 100644 index 000000000000..5f30620277be --- /dev/null +++ b/drivers/misc/mikrobus/mikrobus_manifest.c @@ -0,0 +1,503 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mikroBUS manifest parsing, an + * extension to Greybus Manifest Parsing + * under drivers/greybus/manifest.c + * + * Copyright 2014-2015 Google Inc. + * Copyright 2014-2015 Linaro Ltd. + * Copyright 2024 Ayush Singh + */ + +#define pr_fmt(fmt) "mikrobus_manifest:%s: " fmt, __func__ + +#include "linux/gpio/machine.h" +#include "linux/greybus/greybus_manifest.h" +#include "linux/property.h" +#include "mikrobus_manifest.h" + +struct manifest_desc { + struct list_head links; + size_t size; + void *data; + enum greybus_descriptor_type type; +}; + +static void manifest_descriptor_release_all(struct addon_board_info *board) +{ + struct manifest_desc *descriptor, *next; + + list_for_each_entry_safe(descriptor, next, &board->manifest_descs, + links) { + list_del(&descriptor->links); + kfree(descriptor); + } +} + +static int board_descriptor_add(struct addon_board_info *board, + struct greybus_descriptor *desc, size_t size) +{ + struct greybus_descriptor_header *desc_header = &desc->header; + struct manifest_desc *descriptor; + size_t desc_size, expected_size; + + if (size < sizeof(*desc_header)) { + pr_err("short descriptor (%zu < %zu)", size, + sizeof(*desc_header)); + return -EINVAL; + } + + desc_size = le16_to_cpu(desc_header->size); + if (desc_size > size) { + pr_err("incorrect descriptor size (%zu != %zu)", size, + desc_size); + return -EINVAL; + } + + expected_size = sizeof(*desc_header); + switch (desc_header->type) { + case GREYBUS_TYPE_STRING: + expected_size += sizeof(struct greybus_descriptor_string); + expected_size += desc->string.length; + expected_size = ALIGN(expected_size, 4); + break; + case GREYBUS_TYPE_PROPERTY: + expected_size += sizeof(struct greybus_descriptor_property); + expected_size += desc->property.length; + expected_size = ALIGN(expected_size, 4); + break; + case GREYBUS_TYPE_DEVICE: + expected_size += sizeof(struct greybus_descriptor_device); + break; + case GREYBUS_TYPE_MIKROBUS: + expected_size += sizeof(struct greybus_descriptor_mikrobus); + break; + case GREYBUS_TYPE_INTERFACE: + expected_size += sizeof(struct greybus_descriptor_interface); + break; + case GREYBUS_TYPE_CPORT: + expected_size += sizeof(struct greybus_descriptor_cport); + break; + case GREYBUS_TYPE_BUNDLE: + expected_size += sizeof(struct greybus_descriptor_bundle); + break; + case GREYBUS_TYPE_INVALID: + default: + pr_err("invalid descriptor type %d", desc_header->type); + return -EINVAL; + } + + descriptor = kzalloc(sizeof(*descriptor), GFP_KERNEL); + if (!descriptor) + return -ENOMEM; + + descriptor->size = desc_size; + descriptor->data = (char *)desc + sizeof(*desc_header); + descriptor->type = desc_header->type; + list_add_tail(&descriptor->links, &board->manifest_descs); + + return desc_size; +} + +static char *mikrobus_string_get(struct addon_board_info *board, u8 string_id) +{ + struct greybus_descriptor_string *desc_string; + struct manifest_desc *descriptor; + bool found = false; + char *string; + + if (!string_id) + return NULL; + + list_for_each_entry(descriptor, &board->manifest_descs, links) { + if (descriptor->type != GREYBUS_TYPE_STRING) + continue; + + desc_string = descriptor->data; + if (desc_string->id == string_id) { + found = true; + break; + } + } + + if (!found) + return ERR_PTR(-ENOENT); + + string = kmemdup(&desc_string->string, desc_string->length + 1, + GFP_KERNEL); + if (!string) + return ERR_PTR(-ENOMEM); + + string[desc_string->length] = '\0'; + + return string; +} + +static void mikrobus_state_get(struct addon_board_info *board) +{ + struct greybus_descriptor_mikrobus *mikrobus; + struct greybus_descriptor_interface *interface; + struct manifest_desc *descriptor; + bool found = false; + size_t i; + + list_for_each_entry(descriptor, &board->manifest_descs, links) { + if (descriptor->type == GREYBUS_TYPE_MIKROBUS) { + mikrobus = descriptor->data; + found = true; + break; + } + } + + if (!found) { + pr_err("mikrobus descriptor not found"); + return; + } + + for (i = 0; i < MIKROBUS_PORT_PIN_COUNT; i++) + board->pin_state[i] = mikrobus->pin_state[i]; + + found = false; + list_for_each_entry(descriptor, &board->manifest_descs, links) { + if (descriptor->type == GREYBUS_TYPE_INTERFACE) { + interface = descriptor->data; + found = true; + break; + } + } + + if (!found) { + pr_err("interface descriptor not found"); + return; + } + + board->name = mikrobus_string_get(board, interface->product_stringid); +} + +static struct property_entry * +mikrobus_property_entry_get(struct addon_board_info *board, u8 *prop_link, + int num_properties) +{ + struct greybus_descriptor_property *desc_property; + struct manifest_desc *descriptor; + struct property_entry *properties; + bool found = false; + char *prop_name; + int i, ret; + u64 *val_u64; + u32 *val_u32; + u16 *val_u16; + u8 *val_u8; + + properties = kcalloc(num_properties, sizeof(*properties), GFP_KERNEL); + if (!properties) + return ERR_PTR(-ENOMEM); + + for (i = 0; i < num_properties; i++) { + list_for_each_entry(descriptor, &board->manifest_descs, links) { + if (descriptor->type != GREYBUS_TYPE_PROPERTY) + continue; + + desc_property = descriptor->data; + if (desc_property->id == prop_link[i]) { + found = true; + break; + } + } + + if (!found) { + ret = -ENOENT; + goto early_exit; + } + + prop_name = mikrobus_string_get( + board, desc_property->propname_stringid); + if (!prop_name) { + ret = -ENOENT; + goto early_exit; + } + + switch (desc_property->type) { + case MIKROBUS_PROPERTY_TYPE_U8: + val_u8 = kmemdup(&desc_property->value, + (desc_property->length) * sizeof(u8), + GFP_KERNEL); + if (desc_property->length == 1) + properties[i] = + PROPERTY_ENTRY_U8(prop_name, *val_u8); + else + properties[i] = PROPERTY_ENTRY_U8_ARRAY_LEN( + prop_name, (void *)desc_property->value, + desc_property->length); + break; + case MIKROBUS_PROPERTY_TYPE_U16: + val_u16 = kmemdup(&desc_property->value, + (desc_property->length) * sizeof(u16), + GFP_KERNEL); + if (desc_property->length == 1) + properties[i] = + PROPERTY_ENTRY_U16(prop_name, *val_u16); + else + properties[i] = PROPERTY_ENTRY_U16_ARRAY_LEN( + prop_name, (void *)desc_property->value, + desc_property->length); + break; + case MIKROBUS_PROPERTY_TYPE_U32: + val_u32 = kmemdup(&desc_property->value, + (desc_property->length) * sizeof(u32), + GFP_KERNEL); + if (desc_property->length == 1) + properties[i] = + PROPERTY_ENTRY_U32(prop_name, *val_u32); + else + properties[i] = PROPERTY_ENTRY_U32_ARRAY_LEN( + prop_name, (void *)desc_property->value, + desc_property->length); + break; + case MIKROBUS_PROPERTY_TYPE_U64: + val_u64 = kmemdup(&desc_property->value, + (desc_property->length) * sizeof(u64), + GFP_KERNEL); + if (desc_property->length == 1) + properties[i] = + PROPERTY_ENTRY_U64(prop_name, *val_u64); + else + properties[i] = PROPERTY_ENTRY_U64_ARRAY_LEN( + prop_name, (void *)desc_property->value, + desc_property->length); + break; + default: + ret = -EINVAL; + goto early_exit; + } + } + return properties; + +early_exit: + kfree(properties); + return ERR_PTR(ret); +} + +static u8 *mikrobus_property_link_get(struct addon_board_info *board, + u8 prop_id, + struct board_device_info *board_dev, + u8 prop_type) +{ + struct greybus_descriptor_property *desc_property; + struct manifest_desc *descriptor; + bool found = false; + u8 *val_u8; + + if (!prop_id) + return NULL; + + list_for_each_entry(descriptor, &board->manifest_descs, links) { + if (descriptor->type != GREYBUS_TYPE_PROPERTY) + continue; + + desc_property = descriptor->data; + if (desc_property->id == prop_id && + desc_property->type == prop_type) { + found = true; + break; + } + } + + if (!found) + return ERR_PTR(-ENOENT); + + val_u8 = kmemdup(&desc_property->value, desc_property->length, + GFP_KERNEL); + if (prop_type == MIKROBUS_PROPERTY_TYPE_GPIO) + board_dev->num_gpio_resources = desc_property->length; + else if (prop_type == MIKROBUS_PROPERTY_TYPE_PROPERTY) + board_dev->num_properties = desc_property->length; + + return val_u8; +} + +static int +mikrobus_manifest_attach_device(struct addon_board_info *board, + struct greybus_descriptor_device *dev_desc) +{ + struct greybus_descriptor_property *desc_property; + u8 *gpio_desc_link, *prop_link, *gpioval; + struct board_device_info *board_dev; + struct gpiod_lookup_table *lookup; + struct manifest_desc *descriptor; + int ret, i; + + board_dev = kzalloc(sizeof(*board_dev), GFP_KERNEL); + if (!board_dev) + return -ENOMEM; + + board_dev->id = dev_desc->id; + board_dev->drv_name = + mikrobus_string_get(board, dev_desc->driver_stringid); + if (!board_dev->drv_name) { + ret = -ENOENT; + goto err_free_board_dev; + } + + board_dev->protocol = dev_desc->protocol; + board_dev->reg = dev_desc->reg; + board_dev->irq = dev_desc->irq; + board_dev->irq_type = dev_desc->irq_type; + board_dev->max_speed_hz = le32_to_cpu(dev_desc->max_speed_hz); + board_dev->mode = dev_desc->mode; + pr_info("parsed device %d, driver=%s", board_dev->id, + board_dev->drv_name); + + if (dev_desc->prop_link > 0) { + prop_link = mikrobus_property_link_get( + board, dev_desc->prop_link, board_dev, + MIKROBUS_PROPERTY_TYPE_PROPERTY); + if (!prop_link) { + ret = -ENOENT; + goto err_free_board_dev; + } + + pr_info("device %d, number of properties=%d", board_dev->id, + board_dev->num_properties); + board_dev->properties = mikrobus_property_entry_get( + board, prop_link, board_dev->num_properties); + } + + if (dev_desc->gpio_link > 0) { + gpio_desc_link = mikrobus_property_link_get( + board, dev_desc->gpio_link, board_dev, + MIKROBUS_PROPERTY_TYPE_GPIO); + if (!gpio_desc_link) { + ret = -ENOENT; + goto err_free_board_dev; + } + + pr_info("device %d, number of gpio resource=%d", board_dev->id, + board_dev->num_gpio_resources); + lookup = kzalloc(struct_size(lookup, table, + board_dev->num_gpio_resources), + GFP_KERNEL); + if (!lookup) { + ret = -ENOMEM; + goto err_free_board_dev; + } + + for (i = 0; i < board_dev->num_gpio_resources; i++) { + list_for_each_entry(descriptor, &board->manifest_descs, + links) { + if (descriptor->type != GREYBUS_TYPE_PROPERTY) + continue; + + desc_property = descriptor->data; + if (desc_property->id == gpio_desc_link[i]) { + gpioval = desc_property->value; + lookup->table[i].chip_hwnum = + gpioval[0]; + lookup->table[i].flags = gpioval[1]; + lookup->table[i] + .con_id = mikrobus_string_get( + board, + desc_property + ->propname_stringid); + break; + } + } + } + board_dev->gpio_lookup = lookup; + } + + list_add_tail(&board_dev->links, &board->devices); + return 0; + +err_free_board_dev: + kfree(board_dev); + return ret; +} + +static int mikrobus_manifest_parse_devices(struct addon_board_info *board) +{ + struct greybus_descriptor_device *desc_device; + struct manifest_desc *desc, *next; + int ret, devcount = 0; + + list_for_each_entry_safe(desc, next, &board->manifest_descs, links) { + if (desc->type != GREYBUS_TYPE_DEVICE) + continue; + + desc_device = desc->data; + ret = mikrobus_manifest_attach_device(board, desc_device); + devcount++; + } + + return devcount; +} + +static size_t mikrobus_manifest_header_validate(void *data, size_t size) +{ + struct greybus_manifest_header *header = data; + u16 manifest_size = le16_to_cpu(header->size); + + if (manifest_size < sizeof(*header)) { + pr_err("short manifest (%zu < %zu)", size, sizeof(*header)); + return -EINVAL; + } + + if (header->version_major > MIKROBUS_VERSION_MAJOR) { + pr_err("manifest version too new (%u.%u > %u.%u)", + header->version_major, header->version_minor, + MIKROBUS_VERSION_MAJOR, MIKROBUS_VERSION_MINOR); + return -EINVAL; + } + + return manifest_size; +} + +int mikrobus_manifest_parse(struct addon_board_info *board, void *data, + size_t size) +{ + struct greybus_manifest_header *header; + struct greybus_manifest *manifest; + struct greybus_descriptor *desc; + int dev_count, desc_size, ret; + u16 manifest_size; + + if (size < sizeof(*header)) { + pr_err("short manifest (%zu < %zu)", size, sizeof(*header)); + return -EINVAL; + } + + ret = mikrobus_manifest_header_validate(data, size); + if (ret < 0) { + pr_err("invalid manifest header: %u", manifest_size); + return ret; + } + + manifest = data; + manifest_size = ret; + + if (manifest_size != size) { + pr_err("invalid manifest size(%zu < %u)", size, manifest_size); + return -EINVAL; + } + + desc = manifest->descriptors; + size -= sizeof(*header); + while (size) { + desc_size = board_descriptor_add(board, desc, size); + if (desc_size < 0) { + pr_err("invalid manifest descriptor, size: %u", + desc_size); + return -EINVAL; + } + + desc = (void *)desc + desc_size; + size -= desc_size; + } + + mikrobus_state_get(board); + dev_count = mikrobus_manifest_parse_devices(board); + pr_info("%s manifest parsed with %d devices", board->name, dev_count); + manifest_descriptor_release_all(board); + + return dev_count; +} diff --git a/drivers/misc/mikrobus/mikrobus_manifest.h b/drivers/misc/mikrobus/mikrobus_manifest.h new file mode 100644 index 000000000000..39ae53a25fc4 --- /dev/null +++ b/drivers/misc/mikrobus/mikrobus_manifest.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * mikroBUS manifest definition + * extension to Greybus Manifest Definition + * + * Copyright 2014-2015 Google Inc. + * Copyright 2014-2015 Linaro Ltd. + * + * Released under the GPLv2 and BSD licenses. + */ + +#ifndef __MIKROBUS_MANIFEST_H +#define __MIKROBUS_MANIFEST_H + +#include "mikrobus_core.h" + +/* + * mikrobus_manifest_header - parse mikroBUS manifest + * + * @info: addon board info structure to populate with parsed information + * @data: pointer to the manifest blob + * @size: size of the manifest blob + * + * returns: number of devices on success, negative error code on failure + */ +int mikrobus_manifest_parse(struct addon_board_info *info, void *data, + size_t size); + +#endif /* __MIKROBUS_MANIFEST_H */ From patchwork Sun Mar 17 19:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13594830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE30CC54E67 for ; Sun, 17 Mar 2024 19:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hSPTt19xaKsJcgzk1hYPNaVFYhIDbiAaZDvCKtLssK4=; b=f63RDCrn+03g66 QDn81dYEQN+Y3vOl/YcVUOqwMtPV7BbAZVrUFAwfgeuSPIX35pV3WL/Mww4ZL95JoDuuUgtQYN7W2 bhuygIU9Ho/egiNjCW3zcR7QPgQPFjEpW1HOX95EDoO+tcOEFZLTLA/AwsYnqnicIqi9mVIx0/TMi q1hFKV4KVDZtssLE2uPNnt4QskwBAlQiQvn3cdMBKb//Wx6PbhzBy9eFfEaWQLEdYft2MSjnFdFGf QASiy2oxSeSmq7JNGRN1MPPyfvSWVIneqChzUg+rPF6s8aYS/xujpR862uLKMOQleDINu2D2qPY/t SrT3FuSAiBeikuHY4hRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwLU-00000006EOJ-2tsF; Sun, 17 Mar 2024 19:39:00 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlwLF-00000006EEk-2qNZ for linux-arm-kernel@lists.infradead.org; Sun, 17 Mar 2024 19:38:48 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5a4b35ff84eso256955eaf.2 for ; Sun, 17 Mar 2024 12:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704324; x=1711309124; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OT6hmngmg7LhsdhWQVbZrDuHFIRfbTgzLQihr9TF8as=; b=Ywi/doLoxZ8dGsowbrRPwzM5xeIHgbCkaRsxDmMQ7i+xy5TdhgGMckLgBP3kd8PNVk CHsHnLlnpYtpudrCUxH4Ju6C8I3J3wRqjFevxMM5tL1ZvPWyG0yGYIBP3qgzHZzPU4Bd QpOoKBiUXzANdZf5BopFv9h6azuIBKoYU+C3Hf6t8pUi5M2bu+jaswCrar1DcJj/Q6PK ZGb2QYBfQl2hAvWAYGF0GoT8SPNPJgSfUljXIv1/qSTfF/EmtE361ospKHTzzAw9x7iO 05UoGgNcE8C7oH1gLfpLkyVz9/cmx3kNGkrwASDABXTD6x/aBUwW+33BSMKp9E+/dI0b uQGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710704324; x=1711309124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OT6hmngmg7LhsdhWQVbZrDuHFIRfbTgzLQihr9TF8as=; b=nW45yn3o3gfgJgKwAQfrRtIgmubJl54rZRr2V7IL+sHPmtY4GcYjZ2eyDDg+uJBJF5 CXpNUbywo9cNpMdfhDJiMCpqztJW65r2q9Q181vl2kL8FDviAKlcBWClcKJdZf5HI2Y9 mDE1/x0fT2KydJXOjLvE0aXcICgKpzZQhFgMbYlU+gIWqM/1ipn163VihsV6clCTTY6c H2h2goJrV5Cv5zr0Q3VeqgzQpojieUTavokgASvvg8S9r3k2co59iOrpDS8me9D911L/ HN7l+JofKs0/oQUmuuM0OOQFCXMG/GmSwGMk+n3e8n5lIUxqEaqb4zOeVIPKQAEB8Y7a HAAg== X-Forwarded-Encrypted: i=1; AJvYcCXHqGqq60QRZo2TUGgXOs8vxFtjwe+Ckm0NfM0uXj0FbLLLCVX7JrsBBVSwAlbtnPuJ3Uw3VB4m9+GtY/7YIQOsElT8POYTuj9bPg2LtQ34kcRTCSQ= X-Gm-Message-State: AOJu0Yw2zZM82FXI3eBht3TfI9UqmZz+I7qIS31xjGZFtbNEaqnwrcQu R12Tjh+Sr1ADviLWOZr58wGnOrMpva/jGAEqwk967Em47MeUp4bz X-Google-Smtp-Source: AGHT+IFUpPTaU6PvOX+AKPaPFj4Fu6IdLBC3LDsxuIWxs0yZJKnWwhoTrKzOxe3YGH55CzjEL+bang== X-Received: by 2002:a05:6358:7e92:b0:17c:1e63:d02e with SMTP id o18-20020a0563587e9200b0017c1e63d02emr13107142rwn.2.1710704323604; Sun, 17 Mar 2024 12:38:43 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id st6-20020a17090b1fc600b0029bbdc920besm6125995pjb.44.2024.03.17.12.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 12:38:43 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org (open list) Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, lorforlinux@beagleboard.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Vaishnav M A , Mark Brown , Johan Hovold , Alex Elder , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/TEXAS INSTRUMENTS K3 ARCHITECTURE), linux-spi@vger.kernel.org (open list:SPI SUBSYSTEM), greybus-dev@lists.linaro.org (moderated list:GREYBUS SUBSYSTEM), Vaishnav M A Subject: [PATCH v4 5/5] dts: ti: k3-am625-beagleplay: Add mikroBUS Date: Mon, 18 Mar 2024 01:07:13 +0530 Message-ID: <20240317193714.403132-6-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240317193714.403132-1-ayushdevel1325@gmail.com> References: <20240317193714.403132-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_123845_973616_BEB85006 X-CRM114-Status: GOOD ( 12.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DONOTMERGE this patch depends on patch 1 Add mikroBUS connector support for Beagleplay. Co-developed-by: Vaishnav M A Signed-off-by: Vaishnav M A Signed-off-by: Ayush Singh --- .../arm64/boot/dts/ti/k3-am625-beagleplay.dts | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts b/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts index a34e0df2ab86..e1dce1b80153 100644 --- a/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts +++ b/arch/arm64/boot/dts/ti/k3-am625-beagleplay.dts @@ -29,6 +29,7 @@ aliases { i2c3 = &main_i2c3; i2c4 = &wkup_i2c0; i2c5 = &mcu_i2c0; + mikrobus0 = &mikrobus0; mmc0 = &sdhci0; mmc1 = &sdhci1; mmc2 = &sdhci2; @@ -230,6 +231,38 @@ simple-audio-card,codec { }; }; + mikrobus0: mikrobus-connector { + compatible = "mikrobus-connector"; + pinctrl-names = "default", "pwm_default", "pwm_gpio", + "uart_default", "uart_gpio", "i2c_default", + "i2c_gpio", "spi_default", "spi_gpio"; + pinctrl-0 = <&mikrobus_gpio_pins_default>; + pinctrl-1 = <&mikrobus_pwm_pins_default>; + pinctrl-2 = <&mikrobus_pwm_pins_gpio>; + pinctrl-3 = <&mikrobus_uart_pins_default>; + pinctrl-4 = <&mikrobus_uart_pins_gpio>; + pinctrl-5 = <&mikrobus_i2c_pins_default>; + pinctrl-6 = <&mikrobus_i2c_pins_gpio>; + pinctrl-7 = <&mikrobus_spi_pins_default>; + pinctrl-8 = <&mikrobus_spi_pins_gpio>; + pwms = <&ecap2 0 500000 0>; + i2c-adapter = <&main_i2c3>; + spi-controller = <&main_spi2>; + uart = <&main_uart5>; + spi-cs = <0 1>; + mikrobus-gpios = <&main_gpio1 11 GPIO_ACTIVE_HIGH>, + <&main_gpio1 9 GPIO_ACTIVE_HIGH>, + <&main_gpio1 24 GPIO_ACTIVE_HIGH>, + <&main_gpio1 25 GPIO_ACTIVE_HIGH>, + <&main_gpio1 22 GPIO_ACTIVE_HIGH>, + <&main_gpio1 23 GPIO_ACTIVE_HIGH>, + <&main_gpio1 7 GPIO_ACTIVE_HIGH>, + <&main_gpio1 8 GPIO_ACTIVE_HIGH>, + <&main_gpio1 14 GPIO_ACTIVE_HIGH>, + <&main_gpio1 13 GPIO_ACTIVE_HIGH>, + <&main_gpio1 12 GPIO_ACTIVE_HIGH>, + <&main_gpio1 10 GPIO_ACTIVE_HIGH>; + }; }; &main_pmx0 { @@ -389,6 +422,18 @@ AM62X_IOPAD(0x01f0, PIN_OUTPUT, 5) /* (A18) EXT_REFCLK1.CLKOUT0 */ >; }; + mikrobus_pwm_pins_default: mikrobus-pwm-default-pins { + pinctrl-single,pins = < + AM62X_IOPAD(0x01a4, PIN_INPUT, 2) /* (B20) MCASP0_ACLKX.ECAP2_IN_APWM_OUT */ + >; + }; + + mikrobus_pwm_pins_gpio: mikrobus-pwm-gpio-pins { + pinctrl-single,pins = < + AM62X_IOPAD(0x01a4, PIN_INPUT, 7) /* (B20) MCASP0_ACLKX.GPIO1_11 */ + >; + }; + mikrobus_i2c_pins_default: mikrobus-i2c-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x01d0, PIN_INPUT_PULLUP, 2) /* (A15) UART0_CTSn.I2C3_SCL */ @@ -396,6 +441,13 @@ AM62X_IOPAD(0x01d4, PIN_INPUT_PULLUP, 2) /* (B15) UART0_RTSn.I2C3_SDA */ >; }; + mikrobus_i2c_pins_gpio: mikrobus-i2c-gpio-pins { + pinctrl-single,pins = < + AM62X_IOPAD(0x01d0, PIN_INPUT, 7) /* (A15) UART0_CTSn.GPIO1_22 */ + AM62X_IOPAD(0x01d4, PIN_INPUT, 7) /* (B15) UART0_RTSn.GPIO1_23 */ + >; + }; + mikrobus_uart_pins_default: mikrobus-uart-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x01d8, PIN_INPUT, 1) /* (C15) MCAN0_TX.UART5_RXD */ @@ -403,6 +455,13 @@ AM62X_IOPAD(0x01dc, PIN_OUTPUT, 1) /* (E15) MCAN0_RX.UART5_TXD */ >; }; + mikrobus_uart_pins_gpio: mikrobus-uart-gpio-pins { + pinctrl-single,pins = < + AM62X_IOPAD(0x01d8, PIN_INPUT, 7) /* (C15) MCAN0_TX.GPIO1_24 */ + AM62X_IOPAD(0x01dc, PIN_INPUT, 7) /* (E15) MCAN0_RX.GPIO1_25 */ + >; + }; + mikrobus_spi_pins_default: mikrobus-spi-default-pins { pinctrl-single,pins = < AM62X_IOPAD(0x01b0, PIN_INPUT, 1) /* (A20) MCASP0_ACLKR.SPI2_CLK */ @@ -412,6 +471,15 @@ AM62X_IOPAD(0x0198, PIN_INPUT, 1) /* (A19) MCASP0_AXR2.SPI2_D1 */ >; }; + mikrobus_spi_pins_gpio: mikrobus-spi-gpio-pins { + pinctrl-single,pins = < + AM62X_IOPAD(0x0194, PIN_INPUT, 7) /* (B19) MCASP0_AXR3.GPIO1_7 */ + AM62X_IOPAD(0x0198, PIN_INPUT, 7) /* (A19) MCASP0_AXR2.GPIO1_8 */ + AM62X_IOPAD(0x01ac, PIN_INPUT, 7) /* (E19) MCASP0_AFSR.GPIO1_13 */ + AM62X_IOPAD(0x01b0, PIN_INPUT, 7) /* (A20) MCASP0_ACLKR.GPIO1_14 */ + >; + }; + mikrobus_gpio_pins_default: mikrobus-gpio-default-pins { bootph-all; pinctrl-single,pins = < @@ -629,8 +697,6 @@ &main_gpio0 { &main_gpio1 { bootph-all; - pinctrl-names = "default"; - pinctrl-0 = <&mikrobus_gpio_pins_default>; gpio-line-names = "", "", "", "", "", /* 0-4 */ "SPE_RSTN", "SPE_INTN", "MIKROBUS_GPIO1_7", /* 5-7 */ "MIKROBUS_GPIO1_8", "MIKROBUS_GPIO1_9", /* 8-9 */ @@ -803,15 +869,11 @@ it66121_out: endpoint { }; &main_i2c3 { - pinctrl-names = "default"; - pinctrl-0 = <&mikrobus_i2c_pins_default>; clock-frequency = <400000>; status = "okay"; }; &main_spi2 { - pinctrl-names = "default"; - pinctrl-0 = <&mikrobus_spi_pins_default>; status = "okay"; }; @@ -875,8 +937,6 @@ &main_uart1 { }; &main_uart5 { - pinctrl-names = "default"; - pinctrl-0 = <&mikrobus_uart_pins_default>; status = "okay"; }; @@ -926,3 +986,7 @@ &mcasp1 { tx-num-evt = <32>; rx-num-evt = <32>; }; + +&ecap2 { + status = "okay"; +};