admin管理员组

文章数量:1134248

I now access a peripheral device using the SPI interface on the Linux environment.

Access to this device is okay.

I want to change the SPI CLK, but it is not changed by the clk setting value.

The following code is for the SPI Initialization.

int spidev_init(char *rfdev, int mode, int bits, int speed)
{   
    int file;
    int ret;
    
    file = open(rfdev, O_RDWR);
    if (file < 0) {
        printf("%s can't open device!!!\0", rfdev);
        return -1;
    }
    
    /*
     * spi mode
     */
    ret = ioctl(file, SPI_IOC_WR_MODE, &mode);
    if (ret == -1) {
        printf("%s can't set spi mode!!!", rfdev);
        return -2;
    }   
    else
        bit2equ(spi_mode, mode);
    
    ret = ioctl(file, SPI_IOC_RD_MODE, &mode);
    if (ret == -1) {
        printf("%s can't get spi mode!!!", rfdev);
        return -3;
    }
    
    /*
     * bits per word
     */
    ret = ioctl(file, SPI_IOC_WR_BITS_PER_WORD, &bits);
    if (ret == -1) {
        printf("%s can't set bits per word!!!", rfdev);
        return -4;
    } else
        bit2equ(spi_bits, bits); 
    
    ret = ioctl(file, SPI_IOC_RD_BITS_PER_WORD, &bits);
    if (ret == -1) {
        printf("%s can't get bits per word!!!", rfdev);
        return -5;
    }

    /*
     * max speed hz
     */
    ret = ioctl(file, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
    if (ret == -1) {
        printf("%s can't set max speed hz!!!", rfdev);
        return -6;
    } else
        bit2equ(spi_speed, speed);  
    
    ret = ioctl(file, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
    if (ret == -1) {
        printf("%s can't get max speed hz!!!", rfdev);
        return -7;
    }
    
    return file;
}

I think that this code does not have any debug.

The following is the dts script for SPI.

&spi2 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi2_pincfg>;
    pinctrl-1 = <&spi2_pincfg_sleep>;
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";

    spidev@0 {
        compatible = "rohm,dh2228fv";
        reg = <0>;
        spi-max-frequency = <500000>;
//      spi-max-frequency = <1000000>;
//      spi-max-frequency = <25000000>;
    };
};

spi2: ssp@e401e000 {
    compatible = "zinus,zinus-spi";
    reg = <0xE401D000 0x40>;
    interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cru CLK_SSP2_FUNC>, <&cru CLK_SSP2_APB_BUS>;
    clock-names = "spiclk", "apb_pclk";
    resets = <&cru RST_SSP2>;
    reset-names = "spi";
    dmas = <&sysdma ZN_DMA_SPI2_TX 3>, <&sysdma ZN_DMA_SPI2_RX 3>;
    dma-names = "tx", "rx";
    status = "disabled";
};

spi2 {
    spi2_pincfg:spi2_pincfg {
        zinus,pins = <ZN_GPIO_14 4 &config_pull_disable>,
                <ZN_GPIO_15 4 &config_pull_disable>,
                <ZN_GPIO_16 4 &config_pull_disable>,
                <ZN_GPIO_17 4 &config_pull_disable>;
    };

    spi2_pincfg_sleep:spi2-pincfg-sleep {
        zinus,pins = <ZN_GPIO_14 0 &config_pull_disable>,
                <ZN_GPIO_15 0 &config_pull_disable>,
                <ZN_GPIO_16 0 &config_pull_disable>,
                <ZN_GPIO_17 0 &config_pull_disable>;
    };
};

Is there any point to check for changing SPI CLK.

本文标签: linux device driverSPI CLK is not changed by initializing the SPI SetupStack Overflow