Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
resources:tools-software:linux-drivers:iio-dds:ad9834 [27 Apr 2016 17:14]
Lars-Peter Clausen [Example platform device initialization] Fix typo
resources:tools-software:linux-drivers:iio-dds:ad9834 [15 Mar 2019 08:14]
Alexandru Ardelean change platform to DT
Line 37: Line 37:
 | include | [[git.linux.org>​drivers/​staging/​iio/​frequency/​ad9834.h]] | | include | [[git.linux.org>​drivers/​staging/​iio/​frequency/​ad9834.h]] |
  
-====== Example ​platform ​device ​initialization ​======+====== Example device-tree ======
  
-{{page>​software/​linux/​docs/​platform_and_bus_model#​Platform Data&​noheader&​firstseconly&​noeditbtn}}+In the example below, it's assumed that **spi0** is the SPI controller to which the AD983X is attached to. Typically, these are defined in the board device-tree where the AD983X is attached to.
  
-The reference voltage may vary between boards and models. The platform_data for the device'​s "​struct device"​ holds this information.+<code c>
  
-<source trunk/​drivers/​staging/​iio/​dds/​ad9834.h:​ad9834_platform_data{} c linux-kernel>+ &​spi0 ​{ 
 + #address-cells = <​1>;​ 
 + #​size-cells = <0>
 + status = "​okay";​
  
-<code c> + ad9833@0{ 
-/** + #​clock-cells = <0>; 
- * struct ad9834_platform_data - platform specific information + compatible = "​adi,​ad9833";​ 
- ​* ​@mclk:​ master clock in Hz + reg <0>; 
- * @freq0:​ power up freq0 tuning word in Hz + spi-max-frequency ​<1000000>; 
- * @freq1:​ power up freq1 tuning word in Hz + spi-cpol; 
- * @phase0:​ power up phase0 value [0..4095] correlates with 0..2PI + clocks ​<&​osc>;​ 
- * @phase1:​ power up phase1 value [0..4095] correlates with 0..2PI + vcc-supply ​<&​vcc>;​ 
- * @en_div2:​ digital output/2 is passed to the SIGN BIT OUT pin + }; 
- * @en_signbit_msb_out:​ the MSB (or MSB/2) of the DAC data is connected to the + };
- * SIGN BIT OUT pin. en_div2 controls whether it is the MSB +
- * or MSB/2 that is output. if en_signbit_msb_out=false, +
- * the on-board comparator is connected to SIGN BIT OUT +
- */ +
- +
-struct ad9834_platform_data ad9834_pdata = { +
- .mclk = 75000000, +
- .freq0 ​= 1000000, +
- .freq1 = 5000000, +
- .phase0 ​512, +
- .phase1 ​1024, +
- .en_div2 = false, +
- .en_signbit_msb_out = false, +
-};+
 </​code>​ </​code>​
  
-{{page>​software/​linux/​docs/​platform_and_bus_model#​Declaring SPI slave devices&​firstseconly&​noeditbtn}}+This example also references a regulator (vcc-supply) and a clock (osc). These can be left out, in which case it's assumed they are somehow hard-wired on the board to a proper voltage supply and clock source.
  
-Depending on the DDS IC usedyou may need to set the modalias accordinglymatching your part name. +The **compabtible** string can be any of the following:​ 
-It may also required to adjust max_speed_hz. Please consult the datasheetfor maximum spi clock supported by the device in question.+  * adi,ad9833 
 +  * adi,ad9834 
 +  * adi,ad9837 
 +  * adi,ad9838
  
-<code c> +Note thatthe *adi,* prefix can be omitted and this still works. It is preferred to be added to avoid any potential collisions with other drivers from other vendors
-static struct spi_board_info board_spi_board_info[] __initdata = { + 
-#if defined(CONFIG_AD9834) \ +Howeverthe voltage supply ​clock can be defined via device-tree as well
- || defined(CONFIG_AD9834_MODULE) +See example below:
-+
- .modalias = "​ad9834"​, +
- .max_speed_hz = 1000000    /max spi clock (SCK) speed in HZ */ +
- .bus_num = 0, +
- .chip_select = 3/* CS, change it for your board */ +
- .platform_data = &ad9834_pdata,​ /* No spi_driver specific config */ +
- .mode = SPI_MODE_2,​ +
- }, +
-#endif +
-}; +
-</​code>​+
  
 <code c> <code c>
-static int __init board_init(void) + / { 
-+ vcc: fixedregulator@0 ​
- [--snip--]+ compatible = "​regulator-fixed";​ 
 + regulator-name = "fixed-supply";​ 
 + regulator-min-microvolt = <​2500000>;​ 
 + regulator-max-microvolt = <​2500000>;​ 
 + regulator-boot-on;​ 
 + };
  
- spi_register_board_info(board_spi_board_info,​ ARRAY_SIZE(board_spi_board_info));+ osc: oscillator { 
 + #​clock-cells = <​0>;​ 
 + compatible = "​fixed-clock";​ 
 + clock-frequency = <​25000000>;​ 
 + }; 
 + }; 
 +</​code>​
  
- [--snip--] +This assumes that the board has the chips & drivers to generate voltages like this & clock frequencies.
- +
- return 0; +
-+
-arch_initcall(board_init);​ +
-</​code>​+
  
 ====== Adding Linux driver support ====== ====== Adding Linux driver support ======
resources/tools-software/linux-drivers/iio-dds/ad9834.txt · Last modified: 15 Mar 2019 08:14 by Alexandru Ardelean