当前位置:网站首页>Transplant DAC chip mcp4725 to nuc980

Transplant DAC chip mcp4725 to nuc980

2022-07-07 01:21:00 Ti-laser

This article introduces migration DAC chip MCP4725 Methods .

Because the official linux-4.4.x Although there is one mcp4725.c The driver , But this drive is suitable for none dts Old application scenarios , And my system uses dts The tree needs to replace the driver , The specific method is :

From the website linux/mcp4725.c at master · torvalds/linux · GitHub

download mcp4725.c, The downloaded file can only be compiled and used normally after the following adjustments , As follows :

1 Add header file :#include <linux/of_device.h>

2 find IIO_ENUM_AVAILABLE And delete the second parameter , It takes the form of :

IIO_ENUM_AVAILABLE("powerdown_mode",

                           &mcp472x_powerdown_mode_enum[MCP4725]),

        IIO_ENUM_AVAILABLE("powerdown_mode",

                           &mcp472x_powerdown_mode_enum[MCP4726]),

3 find device_get_match_data Change to of_device_get_match_data

 if (dev_fwnode(&client->dev))

                data->id = (uintptr_t)of_device_get_match_data(&client->dev);

        else

         ......

4 Replace include/linux/iio/dac/mcp4725.h For the following :

....

struct mcp4725_platform_data {

bool use_vref;

bool vref_buffered;

};

....

5 Modify file :

drivers/base/property.c +108, allow dev_fwnode  Called externally :

struct fwnode_handle *dev_fwnode(struct device *dev)

{

        return IS_ENABLED(CONFIG_OF) && dev->of_node ?

                &dev->of_node->fwnode : dev->fwnode;

}

EXPORT_SYMBOL_GPL(dev_fwnode);

6 adjustment include/linux/property.h, Declare the output function

struct fwnode_handle *dev_fwnode(struct device *dev);

7   because DAC The chip is attached to I2c1 On the bus , Documents need to be modified nuc980-iot.dtsi, Add blue part :

i2c1: [email protected] {

                        compatible = "nuvoton,nuc980-i2c1";

.........

                        #address-cells = <1>;

                        #size-cells = <0>;

                        [email protected] {

                        compatible = "microchip,mcp4725";

                                reg = <0x61>;

                        };

After the compilation is normal, it will be written into the board and then enter /sys/devices/iio:deviceX You can see the node information , there X Please replace it according to the actual situation of your system .

Can write DA The value is then tested and verified with a multimeter .

echo 2000 > out_voltage0_raw

 

原网站

版权声明
本文为[Ti-laser]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061734550739.html