Hello!
I am trying to make custom SPI protocol driver for custom device (based on 
FPGA, target for us is LOGI-Bone). Now I have a prototype of FPGA device, 
this prototype is Arduino Pro Mini 3.3V.

I am trying to make custom overlay for device tree which has appropriate 
compatible field for my driver.

Here is my overlay:

/dts-v1/;
/plugin/;
/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";


    /* identification */
    part-number = "BB-ARDUINO-ECHO";
    version = "00A0";

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            spi0_pins_s0: spi0_pins_s0 {
                pinctrl-single,pins = <
                        0x150 0x30      /* mcasp0_aclkx.spi0_sclk, 
INPUT_PULLUP  | MODE0 */
                        0x154 0x30      /* mcasp0_fsx.spi0_d0,     
INPUT_PULLUP  | MODE0 */
                        0x158 0x10      /* mcasp0_axr0.spi0_d1,   
 OUTPUT_PULLUP | MODE0 */
                        0x15c 0x10      /* mcasp0_ahclkr.spi0_cs0, 
OUTPUT_PULLUP | MODE0 */
                >;
            };
        };
    };
    fragment@1 {
        target = <&spi0>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins_s0>;
            ardiuno_echo@0 {
                compatible = "arduino,pro-mini-spi-generic";
                reg = <0>;
                spi-max-frequency = <100000>;
            };
        };
    };
};

And here is my code for getting info from device tree:

static int spi_protocol_generic_probe(struct spi_device *spi)
{
int err, ret;
 int devData = 0;
 const struct of_device_id *match;


 struct device_node *of_target_node;
 u32 max_speed_arduino = 0;


 const char *of_compt_str = kcalloc(sizeof(char), 255, GFP_KERNEL);


 __spi_device_internal = spi;
 default_values.speed_hz = spi->max_speed_hz;
 default_values.mode = spi->mode;
 default_values.bits_per_word = spi->bits_per_word;


 debug_printk("spi-protocol-generic: default speed is %d Hz\n",
     default_values.speed_hz);


 // check and read data from of_device_id...
 match = of_match_device(spi_protocol_generic_of_match, &spi->dev);
 if (!match) {
 debug_printk("device not found in device tree...\n");
 return -1;
 }
 of_target_node = of_find_compatible_node(NULL, NULL, match->compatible);
 if (!of_target_node) {
 of_node_put(of_target_node);
 debug_printk("no compatible devices in DT!\n");
 }


 // Here we can use of_get_property, but I prefer more readable
 // code insted of mire obvious
// ret = of_property_read_u32(of_target_node, "spi-max-frequency",
//   &max_speed_arduino);
 max_speed_arduino = *(u32 *)of_get_property(of_target_node, 
"spi-max-frequency", NULL); 


 if (ret) {
 debug_printk("cannot find property in DT node, status %d\n",
     ret);
 return ret;
 } else {
 debug_printk("freq is %x Hz\n", max_speed_arduino);
 }


 spi->bits_per_word = 8;
 spi->mode = SPI_MODE_0;
 spi->max_speed_hz = max_speed_arduino;
 err = spi_setup(spi);


 if (err < 0) {
 printk(KERN_DEBUG "spi-protocol-generic: spi_setup failed!\n");
 return err;
 } else {
 printk(KERN_DEBUG "spi-protocol-generic: now speed is %d Hz\n",
       spi->max_speed_hz);
 }
// ... and so on
}



I can access to every field of my DT node, but every time I set any 
spi-max-freqency in device tree overlay, I cannot read it properly! Even 
from sysfs:


-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/558551a3-d32a-4e41-9cca-1df5cf6a32e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to