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