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: 781040 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A632A1F94C; Sun, 17 Mar 2024 19:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704293; cv=none; b=M7/2YdIeKOQ+7DbzXxaOF8SrI5TfQkAcK4tLiE492IKkSRbddkZEN5NS1dEsHGprYm5FqMcnveBRRYNDrjiOumz7ewMpmes8u+N8HiCelhWuN98h5dF1i8Pi1g10Wa8qD/g8ea4YlOAf3fY8yk+KdkKQp1xDZSBMu3lJwMYgN+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704293; c=relaxed/simple; bh=NepZd0V4JR54PtTOjVgHeyw+ssv5u+8D6uhP/rktb+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RbYn6TJkOA8tSFLzWWDzKi2XYypNNJUHSg/MUuyrj7Kr508IaffLTcxQhv1EyfMb/hyaYIxrPRTGVQyxOjLqXMLNcz8z9k11hjarxeyOkZHvPUsdAeSAYNr1F+UbsRclqJZwlFmZXlCDt4hMTU07PTgPvxI0iX1lMRLPw89InmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MGeX8yTJ; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MGeX8yTJ" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-29fb12a22afso83161a91.3; 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=vger.kernel.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=MGeX8yTJdLZMq1orLf85u120H1uTOPHNU/dKakwaX/Wp7GABbPDA8fK03Q7KlGco+A +pb/yei3jnMAG9+OJ1IW3/TCxwGmN7927Qx1PU05UpTPC/MlTih3Ft9VGlDpueoPYHsc IsbQ+TA7H6OTsBuayvtUxnnwWu3r3abd/eRsZQYbUY9VNBl/lJx5ZtQV0fajiZIL3nU5 5h1WQlCAEHcBQrsWzYi5ucWnhnaWQNsSbkHRBl5GXKLIalstQVGGBxSdf6aaSQnDOah6 mReyma8XtyUUzlkHkz2Tk04XYSh7EJDOjd5pJhd7LC94VOm6TWOk6tka8C7D5JFFNCok lJOw== 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=dlGUUFRkvhI5sKippqDoQ+O0nolI9XC7J9F4ES8pvo6KsMMCs+ntQLb/JETL5LciE2 5cEwjorgaTjzxJ8oCPkiowyG1yzKGC1nraSViAGO6yuwfhO4awPiYnEQ+otUgACuRULj 3IXrGLv37Bqer448T555U+ZnK7wo8OIdmFkqapLCno1R/wRm0Rb37kMHYhRZQWV23mzk sLLjheArDXJBp21R23cMIRkEiK9hPKBBFIlggqjUvA5EV4HdiqLX9Mim+YsQNdvnpWzB 2juALRQk/c3ZvYp5fnnaV2Aq3LVF4JEjSPzK6gEmmqImj1o5nfLqxGvUta02s8pDUJOI EJyg== X-Forwarded-Encrypted: i=1; AJvYcCUXYbS0iJHv0v1x9q0cMW5jONQfjbhWlGzX6j75BXoq20GSaRp+80Sqivl/7tyNYWROwSQ6rR0gKPyNANRkBb10Zd2QVA6VvubiaQiNMILOY5uI+fvak9EuXhUbiDyNZ6FP4CQ3LQ== X-Gm-Message-State: AOJu0Yx4w4eJ6skXBTYzpMwodFs6xA60pCrP8zRbivUYPQKzhTjs/nxl 64ejfE6OYaWVdAylY0SVar2jYl5gUPvtJfHJZxsaTMZHSd4zV6SKUDygAnq8pK+kRg== 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> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 780899 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B8591EEF7; Sun, 17 Mar 2024 19:38:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704301; cv=none; b=uqzESdjsRQ6RghSXDMRorPNIm3Mg30vDd6QXt8hVNRALaiNF7yd99SNG1b5SKr8Ve+9eJKjUrc2zX5o2GqrAmBbLzng1a4wL2535EsyoZ1TY7Tvr8HVZEYmeWxajuv2vjWn/zteTHxtkGPs2ouAaNvXRMhZMBdf1bwyeoYjIi4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704301; c=relaxed/simple; bh=3F1Z9Uv5v/ZkHS5WWh6yiLmCqTUYZ+P/5oKzWizj12Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kaZx14dx7+YRmNKJSvAhV1GAsUPzmbwKux+C23zMwLPK8bCmRFOZU609ZBljWrv+IADzMfbjXfHhokelc+fomVKKWxcdXJmDvmUvP1bogy6cRWWwrm3urp49MqPNwR9T+NSxxc9HYxCV94Jnd2Xdi2vZRxvpJIMYS5oOFLtBNZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=euIleBCg; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="euIleBCg" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e6ade6a66aso3324658b3a.3; Sun, 17 Mar 2024 12:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704299; x=1711309099; darn=vger.kernel.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=euIleBCgb/W06cBlpD+PvBPN9/e+dnz49aYr0R1MXfnPlRZgXcBTszSOoAgDlstnNM kOjqS2ywY/0xrvApSNLWEnr0dcLRDJBAhAZmn//406aIHEKcXKOW1MxL6DXeVIfTELNU cCaQkftk4aiXLE8cpy4FYgjyyZ4I8YR96V/y5io2+2LCMy9RKlxXLnUKTk8Ny8wGUK9y nF6bBADYwR7wTTtOuCKJS8GK+IFT5MDnKhowbz+kSPa89ordDiw9OUB1bzE9BXuPVdLP pD9FHjRTkjxdJ4LeoK3qM+GigXwbPVQnpkzt9KrqNd75DGZt73DvQFwfmrB5iWJL+HQE 5s7w== 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=V3bXKdVJUdmAeDkRxp+re0juFy6zjGLwa8knkuJz+F5GrMi+NWbQIWLixjXK+3I8Jc 1mo5iKUOBdHRMAdVeqZe/EcnIjWRkwdarl70bQp18er6vdP2fpc3vD8qfGAjN3S1BUXq CpD2hgii1vNWYsMaUXU4j1MHJZm1tcE9g6B3rjU/30mi/lrz1jVReXA62UqSjX6dPrP7 8tiJME5mh+rgtajlCg+MuVspMc4rKHQmROsTA5nEXZpneQe+h/qras7ZDWrp68bu9zwc 9PHRZA+OVkCwLFUj4N2Q+ZuTmZ9cUTGHDf04tXMzG7VzPBNnL0QcFfrFL6KoRH4yBnCI 0pog== X-Forwarded-Encrypted: i=1; AJvYcCV1K2Am6tjyergYgT65BxAQDV/1sA8+ISo7H+GFKAUu4lDQzFJCdHmIlgv3guozdNFOVjxX9IVa6WXa04wYxEWttSYskHWj6Z+R07sXcObKd4l80DzX0DF8Z7tThpmpEmWv0/kG+w== X-Gm-Message-State: AOJu0Yyn2GaUycRJ3FH3wTlNG/44CHhFkXy+gq+HQBxO8f8qxWSLgMbh GQK/An5BsIa0YTjr4ZjVD5vwYrnQO7WGrPQL8Fme1u7RVRv4LD9JYNNlTySCyWA= 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> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 781039 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B439210EC; Sun, 17 Mar 2024 19:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704310; cv=none; b=tVWUaney2Sw+MP0XZF8PCRsRMu9/A5unXDkXQM7018U/cVkaUhRtLNTIlwk2sUBeSs3dShZ+2a6khCrdaqEl90FrS8JDVNX+0VTfDGjx6ve/WEnw6PwGN7d/uLCEDrVIWq5BI7X3x5ICoHGBUnRCr9cWbr8B8bCoeumhGlmX8BA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704310; c=relaxed/simple; bh=lUHaerA7sm8HS5VEf8GULwhZwvO9fhb5VvvPZ5w1aXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVRqC3Wy2/idW8CHzbinBKjyAaFjWXy9Y81wA9S0LgTcwO43g0urI2az2nRbWoSTr/a7EYJmGxPlIhbBDEmFm+iKFD5lZBrISR5KN6i+PBJyOd6Mm8lBtGLJTsDufuCM/b5s22b+nPKX/hEXwyXRuBdgxp/2N9EPEV4Rxi7gP3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hxrVru5O; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hxrVru5O" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-29f69710cbbso687279a91.1; Sun, 17 Mar 2024 12:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704307; x=1711309107; darn=vger.kernel.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=hxrVru5O3Cre08TFhHhN7tPR4O/p6APp+RNLa6G3LIaKLPAmodJrjG/xenZUoGrqSY K/kyQ2cbq75Gl330n6ZMskHD9Zr/CfBC7C2hKdSDrEmvM8phB+Sb1R1aRpLwSI8k34Mw PtcBQmSa1AgbWLLeYLfmqbzgwz2HGXIxCEyqpLQsYI6jb9C7OvFCuH2ogvifrW2bWAyi ns/fGfFaVGSIYHj1/kegkdpEsC5EpI4Ubjs9czRg3LmPtp8REP3asBGPUAKmMKRKv23E vSPItUJWXLHIQD4oTCutOl1BAPKz1S8ximIifhuHLNVnxIZsNKV/1d7LLc5SLN1ecfFe En6g== 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=lBkzshzmHWzZq3puaxbvq8Xee5XohMh24dTe8jQ415fSbPE/Y+poPK4AkOfqwteGnO lIYw9aeTvLQlLk966Ih+oHfGNrAjyIx4/XyBHSFyTe+zBU9kpK2UkeUOsxc+/QLy2smG sRpdpRPqfPbuxVAr7Xqx6bHWCOvSGakeqGLWxOqX55fnG8F/FHZqtfPpzQJCZG/lSK1H 7Gc3+PWTlyqTzPNB18DIu0tWwwY3Fj5AZLgyWWuWfGpPVBdtmlZDVde5SZUpvgcY4UBa MdQv8zexGwXCP7nzxbvd71YeLclJV4oWh8TmmJmqJXCpTba6cTx4mu6NMAK/AMgN7Ojz aB3Q== X-Forwarded-Encrypted: i=1; AJvYcCWFjFhZjxcWHZzZ7yzfK3UvFMLkLchjYkLTVMIXv572T/rxsue/w/MeUcc7eOVuAuTwrtBk+HODcweSisLuWKLTA9k1DZTCX2joldXeLSilQpmPkhBqN7VTNLhou6N3d8NW1KnBRA== X-Gm-Message-State: AOJu0Yy1desVxjkQCKwyLTcV79v6ycwVP5Ugr5ioyH5ywqHFf/qr8gQR oIzq8ooBxoBrXi5U9maZ+m0y5BK41qGoXeUQQb++f1ccKO8mO9f7jvdbPGqPxdg= 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> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 780898 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9360F2134A; Sun, 17 Mar 2024 19:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704320; cv=none; b=AIRom+1ENG+KF2l+z9L7d2Rm8tEdos8+qIomoY11EHZ605NKW5+8kRUbUiuBelfN/5tZJvqkmM2ojZfpn86kXCL6zUOQ4OlFWEzYiBGmy37uxdqRMWgRUog7UUMD1VAZY3LbnuL1DAIgziaWdYYiF5OIXm2GkCdDfZWFtkk4yd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704320; c=relaxed/simple; bh=XoSg38IRIP3vuOnHVR6tVgbooonWmcwUrJ3fe5/rHdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oIQ6UinwPOYqFFxXKZgQi/vD5c6XkNdn/AnBrvOun6mMY0hS3GvjWwxFOPJeOTZ9RwKv2Q7vE0EGoxx1XHgJnvIBNLSPXP9u+FLyMhZUiG/ehiDcqYJPkYprkoogvIYO6Jl5JO/iavXIMeLuM/cn9i+xB5aAR/5h4Iahz307IOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GuNdlqMw; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GuNdlqMw" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6e125818649so1419218a34.1; Sun, 17 Mar 2024 12:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710704316; x=1711309116; darn=vger.kernel.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=GuNdlqMw49dwj2TSfkwCR/RLoAW1uDfXXFJdkth7lUvTtid6/0ybjlzt6XScFtwTNI +Ns1Uji9Cho2wuhhNY1MZwh+NYvP7o0MGrSh8ACxiN7wHpw0UT3EG4uckXuYXV0uRg9X m+0bcpRTpAZgeCcBwjt5ugttB65PmuKfxdMxc2mQWsp2osP0PaWprrVEAqRKhmzo+EAa K/hElXoeSP0m8k1BsDOrPmRnZM8cgWo4SKOqEqrnMfaPDclhCPVrhQ8dp/Qo6eMsCzdh o6JkAxZvbdRou6wjzYDXOWlzmrPV3d4xB7V5R097kgeZGOtA+1xx3CgGyBQVnWryYGW1 a+Xw== 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=cFrMzas451lWof9HT9nQVcS6Vq6pYdahz12RzoIKseciP09o7JBluq3WSnXJUpWOm/ iT6GmUJZB6XOOXG9vqAs3KNQ79Zhta8tqxUQisTrqeXtpKrMwT6Zsw9FsFz5pIMHqWgT fkskapoOwqwUTLsqx64d5d5fdALnHPdkzekqPYyclVMs+Ql2fwRDJ9ne+GLqFuxJzLMN QnobZwrtLW4U+LdUMjiWZzlSmCqTMjd0EZyxFPOTi9nwvbG7PVjNDWUyetD9JunARcwe WgU7QjRZh5170C5rGxKtY5nXELbQtgh0eEmPxEjl1ERtDCvoiuNTz1Wah06yxoxDB75P LcqA== X-Forwarded-Encrypted: i=1; AJvYcCUdUbNlW2BkW2UYy87QXVk+kDN17ymdu16+GERPMJGMhs/SwcVzPUld9xJBiL/8xfKDpuEH85hc2jR9U5j4Y2TZaNfHUswhT4QkudQtM48zHa1xGqxgAuH2BJNpaWKq5F+IYKq85Q== X-Gm-Message-State: AOJu0Yz/L67QmAkjMj52rg1k+pekIMYVs+I50U4vt+8wGH29Og7beQhZ dVfvV3L5zUze9fA2chuBt8n4uvrGxhDVN4m4hkdFunlYaL1odGm/iJ+u5otPCMo= 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> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 781038 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0102420323; Sun, 17 Mar 2024 19:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704326; cv=none; b=Ub8RAI8PGC6m/RyBbJ07f7BwgWYnCDWypVmGSV1uXLv34RBEZTJxUdR+FJfesrTjvbA6FErfJ9wA+Y0i2JPCm7US5badHQar+o8WptqAo3dBEUM6sirmB5zqbwk8/o4ApnJdO/EgCQfg2EVMMjj6AvpWIm24hPq8adP0SGQToEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710704326; c=relaxed/simple; bh=zde3M6Y1JOzRO5e3g2eBRl5mSIHaobfX2LHthOYLsEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gW83p42zpTRAczTj/OqzVG/af+R82Hcc9VZ8Z+WsTfGlx0sA4HQGC83hYdjjpNn2qbCstbt7Ny9wDn2vCn20xJdPHL3DTgDloZ75D65WD9P84MfnuIz4OMw4vXF+nn6dedWi/v62lW43b7W8yt/kMi0+1Kh7oMBMLNs7YL0mUBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NizJg7cn; arc=none smtp.client-ip=209.85.167.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NizJg7cn" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3c37e87756dso1047542b6e.3; 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=vger.kernel.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=NizJg7cnyVai5S0GO+K4gBjYFqL620u6LKUW6bE6P1pGH0kvWObrYMqiL4RKudKO9s XTfEwkCpsFGHeoeFWusAdpuLHJje9pGMq9dC1tQzdN1u19mVSCBLwqkVSYEn1bekVbf5 f4zKqIrZdYXgomlXcfhODq7EOCsOtCxjGredJScpRwhm6gWbsHyHqOGPix/TKu9/cXea ijXfbHfVQXMmBspnfE/ZGBV3vzr9H4nOwMaPX11nH/G1GLwn1AUo7Wm5UsqEgvyoWc7L bXtNDUWewDizE1OeicXWjRV69ncqKgmiQB/HEEXDfHx4zGRRKjcwD9q5Awn0nCrYaf3L uSWQ== 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=Jwiz8sbezvjoMMFafieh1Pm+qjn1Wj4hnQdDuPEhCB5oUGfUcbK++4RE3vgiGw61rS OkEsGMR7NOBz6e73BoYSO6moH6kgulpuIrMt/+9KcKB4I+Gk9BHAppVw/buT5AA+V9iA 95BG6byhkPZj3DsYPiqv3uKWZNfNsnscCS7UndV8EDMmbrG3Ot1njFAfVPAKmjSRUSX/ +VScJtS+c0TWkxO2WZX96bPMMUVdD7e36Z50ZelLygwHSGFHEjRgmkso6GohTJRLGW2g UXvh+CTQO05d1HQFJXXaFj4knrCujgTbUfXZJDVEwQs////lzMe8V7rTMTxGVbey8/hV hHHA== X-Forwarded-Encrypted: i=1; AJvYcCUgz48OcM8HaIEgT+Jf8CLz55NH8WfsEh29LohkTfGxRDqzEa8xFd/3IiqhaB426axdZLVPA70uIe96r7tF++1mQQN390XiGzQUtbGyEBJAobCrS7UEzsoxNbn04nyON8VBdGNvIg== X-Gm-Message-State: AOJu0YzyaoKtOXmLWaTpXihZUDS6WqBzCJg9F01daZnpQ+y6J2jMY/Ey +HuCB1RbXpNgu4GPGySXxDxK8AFoxIqsyQtFfWNV4qC19Kwh58oupitaxOBylJk= 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> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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"; +};