xref: /OK3568_Linux_fs/u-boot/doc/driver-model/i2c-howto.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunHow to port a serial driver to driver model
2*4882a593Smuzhiyun===========================================
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunOver half of the I2C drivers have been converted as at November 2016. These
5*4882a593Smuzhiyunones remain:
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun   adi_i2c
8*4882a593Smuzhiyun   davinci_i2c
9*4882a593Smuzhiyun   fti2c010
10*4882a593Smuzhiyun   ihs_i2c
11*4882a593Smuzhiyun   kona_i2c
12*4882a593Smuzhiyun   lpc32xx_i2c
13*4882a593Smuzhiyun   pca9564_i2c
14*4882a593Smuzhiyun   ppc4xx_i2c
15*4882a593Smuzhiyun   rcar_i2c
16*4882a593Smuzhiyun   sh_i2c
17*4882a593Smuzhiyun   sh_sh7734_i2c
18*4882a593Smuzhiyun   soft_i2c
19*4882a593Smuzhiyun   tsi108_i2c
20*4882a593Smuzhiyun   zynq_i2c
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe deadline for this work is the end of June 2017. If no one steps
23*4882a593Smuzhiyunforward to convert these, at some point there may come a patch to remove them!
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunHere is a suggested approach for converting your I2C driver over to driver
26*4882a593Smuzhiyunmodel. Please feel free to update this file with your ideas and suggestions.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun- #ifdef out all your own I2C driver code (#ifndef CONFIG_DM_I2C)
29*4882a593Smuzhiyun- Define CONFIG_DM_I2C for your board, vendor or architecture
30*4882a593Smuzhiyun- If the board does not already use driver model, you need CONFIG_DM also
31*4882a593Smuzhiyun- Your board should then build, but will not work fully since there will be
32*4882a593Smuzhiyun    no I2C driver
33*4882a593Smuzhiyun- Add the U_BOOT_DRIVER piece at the end (e.g. copy tegra_i2c.c for example)
34*4882a593Smuzhiyun- Add a private struct for the driver data - avoid using static variables
35*4882a593Smuzhiyun- Implement each of the driver methods, perhaps by calling your old methods
36*4882a593Smuzhiyun- You may need to adjust the function parameters so that the old and new
37*4882a593Smuzhiyun    implementations can share most of the existing code
38*4882a593Smuzhiyun- If you convert all existing users of the driver, remove the pre-driver-model
39*4882a593Smuzhiyun    code
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunIn terms of patches a conversion series typically has these patches:
42*4882a593Smuzhiyun- clean up / prepare the driver for conversion
43*4882a593Smuzhiyun- add driver model code
44*4882a593Smuzhiyun- convert at least one existing board to use driver model serial
45*4882a593Smuzhiyun- (if no boards remain that don't use driver model) remove the old code
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunThis may be a good time to move your board to use device tree also. Mostly
48*4882a593Smuzhiyunthis involves these steps:
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun- define CONFIG_OF_CONTROL and CONFIG_OF_SEPARATE
51*4882a593Smuzhiyun- add your device tree files to arch/<arch>/dts
52*4882a593Smuzhiyun- update the Makefile there
53*4882a593Smuzhiyun- Add stdout-path to your /chosen device tree node if it is not already there
54*4882a593Smuzhiyun- build and get u-boot-dtb.bin so you can test it
55*4882a593Smuzhiyun- Your drivers can now use device tree
56*4882a593Smuzhiyun- For device tree in SPL, define CONFIG_SPL_OF_CONTROL
57