€•‚Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ-/translations/zh_CN/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ-/translations/zh_TW/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ-/translations/it_IT/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ-/translations/ja_JP/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ-/translations/ko_KR/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ-/translations/sp_SP/i2c/instantiating-devices”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒHow to instantiate I2C devices”h]”hŒHow to instantiate I2C devices”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒG/var/lib/git/docbuild/linux/Documentation/i2c/instantiating-devices.rst”h KubhŒ paragraph”“”)”}”(hXlUnlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are several ways to achieve this, depending on the context and requirements.”h]”hXlUnlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are several ways to achieve this, depending on the context and requirements.”…””}”(hh¹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒ,Method 1: Declare the I2C devices statically”h]”hŒ,Method 1: Declare the I2C devices statically”…””}”(hhÊhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhÇhžhhŸh¶h K ubh¸)”}”(hŒöThis method is appropriate when the I2C bus is a system bus as is the case for many embedded systems. On such systems, each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices which live on this bus.”h]”hŒöThis method is appropriate when the I2C bus is a system bus as is the case for many embedded systems. On such systems, each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices which live on this bus.”…””}”(hhØhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhhÇhžhubh¸)”}”(hŒ{This information is provided to the kernel in a different way on different architectures: device tree, ACPI or board files.”h]”hŒ{This information is provided to the kernel in a different way on different architectures: device tree, ACPI or board files.”…””}”(hhæhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhhÇhžhubh¸)”}”(hŒÕWhen the I2C bus in question is registered, the I2C devices will be instantiated automatically by i2c-core. The devices will be automatically unbound and destroyed when the I2C bus they sit on goes away (if ever).”h]”hŒÕWhen the I2C bus in question is registered, the I2C devices will be instantiated automatically by i2c-core. The devices will be automatically unbound and destroyed when the I2C bus they sit on goes away (if ever).”…””}”(hhôhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhhÇhžhubh¢)”}”(hhh]”(h§)”}”(hŒ&Declare the I2C devices via devicetree”h]”hŒ&Declare the I2C devices via devicetree”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhžhhŸh¶h Kubh¸)”}”(hŒkOn platforms using devicetree, the declaration of I2C devices is done in subnodes of the master controller.”h]”hŒkOn platforms using devicetree, the declaration of I2C devices is done in subnodes of the master controller.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khjhžhubh¸)”}”(hŒExample:”h]”hŒExample:”…””}”(hj!hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K"hjhžhubhŒ literal_block”“”)”}”(hXŠi2c1: i2c@400a0000 { /* ... master properties skipped ... */ clock-frequency = <100000>; flash@50 { compatible = "atmel,24c256"; reg = <0x50>; }; pca9532: gpio@60 { compatible = "nxp,pca9532"; gpio-controller; #gpio-cells = <2>; reg = <0x60>; }; };”h]”hXŠi2c1: i2c@400a0000 { /* ... master properties skipped ... */ clock-frequency = <100000>; flash@50 { compatible = "atmel,24c256"; reg = <0x50>; }; pca9532: gpio@60 { compatible = "nxp,pca9532"; gpio-controller; #gpio-cells = <2>; reg = <0x60>; }; };”…””}”hj1sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”Œforce”‰Œlanguage”Œdts”Œhighlight_args”}”uh1j/hŸh¶h K$hjhžhubh¸)”}”(hŒÜHere, two devices are attached to the bus using a speed of 100kHz. For additional properties which might be needed to set up the device, please refer to its devicetree documentation in Documentation/devicetree/bindings/.”h]”hŒÜHere, two devices are attached to the bus using a speed of 100kHz. For additional properties which might be needed to set up the device, please refer to its devicetree documentation in Documentation/devicetree/bindings/.”…””}”(hjFhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K7hjhžhubeh}”(h]”Œ&declare-the-i2c-devices-via-devicetree”ah ]”h"]”Œ&declare the i2c devices via devicetree”ah$]”h&]”uh1h¡hhÇhžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒ Declare the I2C devices via ACPI”h]”hŒ Declare the I2C devices via ACPI”…””}”(hj_hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj\hžhhŸh¶h K=ubh¸)”}”(hŒœACPI can also describe I2C devices. There is special documentation for this which is currently located at Documentation/firmware-guide/acpi/enumeration.rst.”h]”hŒœACPI can also describe I2C devices. There is special documentation for this which is currently located at Documentation/firmware-guide/acpi/enumeration.rst.”…””}”(hjmhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K?hj\hžhubeh}”(h]”Œ declare-the-i2c-devices-via-acpi”ah ]”h"]”Œ declare the i2c devices via acpi”ah$]”h&]”uh1h¡hhÇhžhhŸh¶h K=ubh¢)”}”(hhh]”(h§)”}”(hŒ&Declare the I2C devices in board files”h]”hŒ&Declare the I2C devices in board files”…””}”(hj†hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjƒhžhhŸh¶h KDubh¸)”}”(hX(In many embedded architectures, devicetree has replaced the old hardware description based on board files, but the latter are still used in old code. Instantiating I2C devices via board files is done with an array of struct i2c_board_info which is registered by calling i2c_register_board_info().”h]”hX(In many embedded architectures, devicetree has replaced the old hardware description based on board files, but the latter are still used in old code. Instantiating I2C devices via board files is done with an array of struct i2c_board_info which is registered by calling i2c_register_board_info().”…””}”(hj”hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KFhjƒhžhubh¸)”}”(hŒExample (from omap2 h4):”h]”hŒExample (from omap2 h4):”…””}”(hj¢hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KLhjƒhžhubj0)”}”(hXustatic struct i2c_board_info h4_i2c_board_info[] __initdata = { { I2C_BOARD_INFO("isp1301_omap", 0x2d), .irq = OMAP_GPIO_IRQ(125), }, { /* EEPROM on mainboard */ I2C_BOARD_INFO("24c01", 0x52), .platform_data = &m24c01, }, { /* EEPROM on cpu card */ I2C_BOARD_INFO("24c01", 0x57), .platform_data = &m24c01, }, }; static void __init omap_h4_init(void) { (...) i2c_register_board_info(1, h4_i2c_board_info, ARRAY_SIZE(h4_i2c_board_info)); (...) }”h]”hXustatic struct i2c_board_info h4_i2c_board_info[] __initdata = { { I2C_BOARD_INFO("isp1301_omap", 0x2d), .irq = OMAP_GPIO_IRQ(125), }, { /* EEPROM on mainboard */ I2C_BOARD_INFO("24c01", 0x52), .platform_data = &m24c01, }, { /* EEPROM on cpu card */ I2C_BOARD_INFO("24c01", 0x57), .platform_data = &m24c01, }, }; static void __init omap_h4_init(void) { (...) i2c_register_board_info(1, h4_i2c_board_info, ARRAY_SIZE(h4_i2c_board_info)); (...) }”…””}”hj°sbah}”(h]”h ]”h"]”h$]”h&]”j?j@jA‰jBŒc”jD}”uh1j/hŸh¶h KNhjƒhžhubh¸)”}”(hŒ}The above code declares 3 devices on I2C bus 1, including their respective addresses and custom data needed by their drivers.”h]”hŒ}The above code declares 3 devices on I2C bus 1, including their respective addresses and custom data needed by their drivers.”…””}”(hjÀhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kghjƒhžhubeh}”(h]”Œ&declare-the-i2c-devices-in-board-files”ah ]”h"]”Œ&declare the i2c devices in board files”ah$]”h&]”uh1h¡hhÇhžhhŸh¶h KDubeh}”(h]”Œ+method-1-declare-the-i2c-devices-statically”ah ]”h"]”Œ,method 1: declare the i2c devices statically”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K ubh¢)”}”(hhh]”(h§)”}”(hŒ,Method 2: Instantiate the devices explicitly”h]”hŒ,Method 2: Instantiate the devices explicitly”…””}”(hjáhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjÞhžhhŸh¶h Klubh¸)”}”(hXìThis method is appropriate when a larger device uses an I2C bus for internal communication. A typical case is TV adapters. These can have a tuner, a video decoder, an audio decoder, etc. usually connected to the main chip by the means of an I2C bus. You won't know the number of the I2C bus in advance, so the method 1 described above can't be used. Instead, you can instantiate your I2C devices explicitly. This is done by filling a struct i2c_board_info and calling i2c_new_client_device().”h]”hXðThis method is appropriate when a larger device uses an I2C bus for internal communication. A typical case is TV adapters. These can have a tuner, a video decoder, an audio decoder, etc. usually connected to the main chip by the means of an I2C bus. You won’t know the number of the I2C bus in advance, so the method 1 described above can’t be used. Instead, you can instantiate your I2C devices explicitly. This is done by filling a struct i2c_board_info and calling i2c_new_client_device().”…””}”(hjïhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KnhjÞhžhubh¸)”}”(hŒ*Example (from the sfe4001 network driver):”h]”hŒ*Example (from the sfe4001 network driver):”…””}”(hjýhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KvhjÞhžhubj0)”}”(hXstatic struct i2c_board_info sfe4001_hwmon_info = { I2C_BOARD_INFO("max6647", 0x4e), }; int sfe4001_init(struct efx_nic *efx) { (...) efx->board_info.hwmon_client = i2c_new_client_device(&efx->i2c_adap, &sfe4001_hwmon_info); (...) }”h]”hXstatic struct i2c_board_info sfe4001_hwmon_info = { I2C_BOARD_INFO("max6647", 0x4e), }; int sfe4001_init(struct efx_nic *efx) { (...) efx->board_info.hwmon_client = i2c_new_client_device(&efx->i2c_adap, &sfe4001_hwmon_info); (...) }”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j?j@jA‰jBj¾jD}”uh1j/hŸh¶h KxhjÞhžhubh¸)”}”(hŒdThe above code instantiates 1 I2C device on the I2C bus which is on the network adapter in question.”h]”hŒdThe above code instantiates 1 I2C device on the I2C bus which is on the network adapter in question.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K‡hjÞhžhubh¸)”}”(hXA variant of this is when you don't know for sure if an I2C device is present or not (for example for an optional feature which is not present on cheap variants of a board but you have no way to tell them apart), or it may have different addresses from one board to the next (manufacturer changing its design without notice). In this case, you can call i2c_new_scanned_device() instead of i2c_new_client_device().”h]”hXŸA variant of this is when you don’t know for sure if an I2C device is present or not (for example for an optional feature which is not present on cheap variants of a board but you have no way to tell them apart), or it may have different addresses from one board to the next (manufacturer changing its design without notice). In this case, you can call i2c_new_scanned_device() instead of i2c_new_client_device().”…””}”(hj(hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KŠhjÞhžhubh¸)”}”(hŒ#Example (from the nxp OHCI driver):”h]”hŒ#Example (from the nxp OHCI driver):”…””}”(hj6hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K‘hjÞhžhubj0)”}”(hXJstatic const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; static int usb_hcd_nxp_probe(struct platform_device *pdev) { (...) struct i2c_adapter *i2c_adap; struct i2c_board_info i2c_info; (...) i2c_adap = i2c_get_adapter(2); memset(&i2c_info, 0, sizeof(struct i2c_board_info)); strscpy(i2c_info.type, "isp1301_nxp", sizeof(i2c_info.type)); isp1301_i2c_client = i2c_new_scanned_device(i2c_adap, &i2c_info, normal_i2c, NULL); i2c_put_adapter(i2c_adap); (...) }”h]”hXJstatic const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; static int usb_hcd_nxp_probe(struct platform_device *pdev) { (...) struct i2c_adapter *i2c_adap; struct i2c_board_info i2c_info; (...) i2c_adap = i2c_get_adapter(2); memset(&i2c_info, 0, sizeof(struct i2c_board_info)); strscpy(i2c_info.type, "isp1301_nxp", sizeof(i2c_info.type)); isp1301_i2c_client = i2c_new_scanned_device(i2c_adap, &i2c_info, normal_i2c, NULL); i2c_put_adapter(i2c_adap); (...) }”…””}”hjDsbah}”(h]”h ]”h"]”h$]”h&]”j?j@jA‰jBj¾jD}”uh1j/hŸh¶h K“hjÞhžhubh¸)”}”(hŒëThe above code instantiates up to 1 I2C device on the I2C bus which is on the OHCI adapter in question. It first tries at address 0x2c, if nothing is found there it tries address 0x2d, and if still nothing is found, it simply gives up.”h]”hŒëThe above code instantiates up to 1 I2C device on the I2C bus which is on the OHCI adapter in question. It first tries at address 0x2c, if nothing is found there it tries address 0x2d, and if still nothing is found, it simply gives up.”…””}”(hjShžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K§hjÞhžhubh¸)”}”(hŒêThe driver which instantiated the I2C device is responsible for destroying it on cleanup. This is done by calling i2c_unregister_device() on the pointer that was earlier returned by i2c_new_client_device() or i2c_new_scanned_device().”h]”hŒêThe driver which instantiated the I2C device is responsible for destroying it on cleanup. This is done by calling i2c_unregister_device() on the pointer that was earlier returned by i2c_new_client_device() or i2c_new_scanned_device().”…””}”(hjahžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K¬hjÞhžhubeh}”(h]”Œ+method-2-instantiate-the-devices-explicitly”ah ]”h"]”Œ,method 2: instantiate the devices explicitly”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Klubh¢)”}”(hhh]”(h§)”}”(hŒ.Method 3: Probe an I2C bus for certain devices”h]”hŒ.Method 3: Probe an I2C bus for certain devices”…””}”(hjzhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjwhžhhŸh¶h K³ubh¸)”}”(hXùSometimes you do not have enough information about an I2C device, not even to call i2c_new_scanned_device(). The typical case is hardware monitoring chips on PC mainboards. There are several dozen models, which can live at 25 different addresses. Given the huge number of mainboards out there, it is next to impossible to build an exhaustive list of the hardware monitoring chips being used. Fortunately, most of these chips have manufacturer and device ID registers, so they can be identified by probing.”h]”hXùSometimes you do not have enough information about an I2C device, not even to call i2c_new_scanned_device(). The typical case is hardware monitoring chips on PC mainboards. There are several dozen models, which can live at 25 different addresses. Given the huge number of mainboards out there, it is next to impossible to build an exhaustive list of the hardware monitoring chips being used. Fortunately, most of these chips have manufacturer and device ID registers, so they can be identified by probing.”…””}”(hjˆhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kµhjwhžhubh¸)”}”(hX>In that case, I2C devices are neither declared nor instantiated explicitly. Instead, i2c-core will probe for such devices as soon as their drivers are loaded, and if any is found, an I2C device will be instantiated automatically. In order to prevent any misbehavior of this mechanism, the following restrictions apply:”h]”hX>In that case, I2C devices are neither declared nor instantiated explicitly. Instead, i2c-core will probe for such devices as soon as their drivers are loaded, and if any is found, an I2C device will be instantiated automatically. In order to prevent any misbehavior of this mechanism, the following restrictions apply:”…””}”(hj–hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K¾hjwhžhubhŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hŒ‚The I2C device driver must implement the detect() method, which identifies a supported device by reading from arbitrary registers.”h]”h¸)”}”(hŒ‚The I2C device driver must implement the detect() method, which identifies a supported device by reading from arbitrary registers.”h]”hŒ‚The I2C device driver must implement the detect() method, which identifies a supported device by reading from arbitrary registers.”…””}”(hj¯hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÄhj«ubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj¦hžhhŸh¶h Nubjª)”}”(hŒ®Only buses which are likely to have a supported device and agree to be probed, will be probed. For example this avoids probing for hardware monitoring chips on a TV adapter. ”h]”h¸)”}”(hŒ­Only buses which are likely to have a supported device and agree to be probed, will be probed. For example this avoids probing for hardware monitoring chips on a TV adapter.”h]”hŒ­Only buses which are likely to have a supported device and agree to be probed, will be probed. For example this avoids probing for hardware monitoring chips on a TV adapter.”…””}”(hjÇhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÆhjÃubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj¦hžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ*”uh1j¤hŸh¶h KÄhjwhžhubh¸)”}”(hŒBExample: See lm90_driver and lm90_detect() in drivers/hwmon/lm90.c”h]”hŒBExample: See lm90_driver and lm90_detect() in drivers/hwmon/lm90.c”…””}”(hjãhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÊhjwhžhubh¸)”}”(hŒÜI2C devices instantiated as a result of such a successful probe will be destroyed automatically when the driver which detected them is removed, or when the underlying I2C bus is itself destroyed, whichever happens first.”h]”hŒÜI2C devices instantiated as a result of such a successful probe will be destroyed automatically when the driver which detected them is removed, or when the underlying I2C bus is itself destroyed, whichever happens first.”…””}”(hjñhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÍhjwhžhubh¸)”}”(hŒÂThose of you familiar with the I2C subsystem of 2.4 kernels and early 2.6 kernels will find out that this method 3 is essentially similar to what was done there. Two significant differences are:”h]”hŒÂThose of you familiar with the I2C subsystem of 2.4 kernels and early 2.6 kernels will find out that this method 3 is essentially similar to what was done there. Two significant differences are:”…””}”(hjÿhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÒhjwhžhubj¥)”}”(hhh]”(jª)”}”(hŒóProbing is only one way to instantiate I2C devices now, while it was the only way back then. Where possible, methods 1 and 2 should be preferred. Method 3 should only be used when there is no other way, as it can have undesirable side effects.”h]”h¸)”}”(hŒóProbing is only one way to instantiate I2C devices now, while it was the only way back then. Where possible, methods 1 and 2 should be preferred. Method 3 should only be used when there is no other way, as it can have undesirable side effects.”h]”hŒóProbing is only one way to instantiate I2C devices now, while it was the only way back then. Where possible, methods 1 and 2 should be preferred. Method 3 should only be used when there is no other way, as it can have undesirable side effects.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÖhjubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubjª)”}”(hXDI2C buses must now explicitly say which I2C driver classes can probe them (by the means of the class bitfield), while all I2C buses were probed by default back then. The default is an empty class which means that no probing happens. The purpose of the class bitfield is to limit the aforementioned undesirable side effects. ”h]”h¸)”}”(hXCI2C buses must now explicitly say which I2C driver classes can probe them (by the means of the class bitfield), while all I2C buses were probed by default back then. The default is an empty class which means that no probing happens. The purpose of the class bitfield is to limit the aforementioned undesirable side effects.”h]”hXCI2C buses must now explicitly say which I2C driver classes can probe them (by the means of the class bitfield), while all I2C buses were probed by default back then. The default is an empty class which means that no probing happens. The purpose of the class bitfield is to limit the aforementioned undesirable side effects.”…””}”(hj,hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÚhj(ubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”jájâuh1j¤hŸh¶h KÖhjwhžhubh¸)”}”(hŒ—Once again, method 3 should be avoided wherever possible. Explicit device instantiation (methods 1 and 2) is much preferred for it is safer and faster.”h]”hŒ—Once again, method 3 should be avoided wherever possible. Explicit device instantiation (methods 1 and 2) is much preferred for it is safer and faster.”…””}”(hjFhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kàhjwhžhubeh}”(h]”Œ-method-3-probe-an-i2c-bus-for-certain-devices”ah ]”h"]”Œ.method 3: probe an i2c bus for certain devices”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K³ubh¢)”}”(hhh]”(h§)”}”(hŒ%Method 4: Instantiate from user-space”h]”hŒ%Method 4: Instantiate from user-space”…””}”(hj_hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj\hžhhŸh¶h Kæubh¸)”}”(hXãIn general, the kernel should know which I2C devices are connected and what addresses they live at. However, in certain cases, it does not, so a sysfs interface was added to let the user provide the information. This interface is made of 2 attribute files which are created in every I2C bus directory: ``new_device`` and ``delete_device``. Both files are write only and you must write the right parameters to them in order to properly instantiate, respectively delete, an I2C device.”h]”(hX.In general, the kernel should know which I2C devices are connected and what addresses they live at. However, in certain cases, it does not, so a sysfs interface was added to let the user provide the information. This interface is made of 2 attribute files which are created in every I2C bus directory: ”…””}”(hjmhžhhŸNh NubhŒliteral”“”)”}”(hŒ``new_device``”h]”hŒ new_device”…””}”(hjwhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1juhjmubhŒ and ”…””}”(hjmhžhhŸNh Nubjv)”}”(hŒ``delete_device``”h]”hŒ delete_device”…””}”(hj‰hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1juhjmubhŒ‘. Both files are write only and you must write the right parameters to them in order to properly instantiate, respectively delete, an I2C device.”…””}”(hjmhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kèhj\hžhubh¸)”}”(hŒÖFile ``new_device`` takes 2 parameters: the name of the I2C device (a string) and the address of the I2C device (a number, typically expressed in hexadecimal starting with 0x, but can also be expressed in decimal.)”h]”(hŒFile ”…””}”(hj¡hžhhŸNh Nubjv)”}”(hŒ``new_device``”h]”hŒ new_device”…””}”(hj©hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1juhj¡ubhŒÃ takes 2 parameters: the name of the I2C device (a string) and the address of the I2C device (a number, typically expressed in hexadecimal starting with 0x, but can also be expressed in decimal.)”…””}”(hj¡hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kðhj\hžhubh¸)”}”(hŒßFile ``delete_device`` takes a single parameter: the address of the I2C device. As no two devices can live at the same address on a given I2C segment, the address is sufficient to uniquely identify the device to be deleted.”h]”(hŒFile ”…””}”(hjÁhžhhŸNh Nubjv)”}”(hŒ``delete_device``”h]”hŒ delete_device”…””}”(hjÉhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1juhjÁubhŒÉ takes a single parameter: the address of the I2C device. As no two devices can live at the same address on a given I2C segment, the address is sufficient to uniquely identify the device to be deleted.”…””}”(hjÁhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kôhj\hžhubh¸)”}”(hŒ Example::”h]”hŒExample:”…””}”(hjáhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kùhj\hžhubj0)”}”(hŒ:# echo eeprom 0x50 > /sys/bus/i2c/devices/i2c-3/new_device”h]”hŒ:# echo eeprom 0x50 > /sys/bus/i2c/devices/i2c-3/new_device”…””}”hjïsbah}”(h]”h ]”h"]”h$]”h&]”j?j@uh1j/hŸh¶h Kûhj\hžhubh¸)”}”(hŒŽWhile this interface should only be used when in-kernel device declaration can't be done, there is a variety of cases where it can be helpful:”h]”hŒWhile this interface should only be used when in-kernel device declaration can’t be done, there is a variety of cases where it can be helpful:”…””}”(hjýhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kýhj\hžhubj¥)”}”(hhh]”(jª)”}”(hŒªThe I2C driver usually detects devices (method 3 above) but the bus segment your device lives on doesn't have the proper class bit set and thus detection doesn't trigger.”h]”h¸)”}”(hŒªThe I2C driver usually detects devices (method 3 above) but the bus segment your device lives on doesn't have the proper class bit set and thus detection doesn't trigger.”h]”hŒ®The I2C driver usually detects devices (method 3 above) but the bus segment your device lives on doesn’t have the proper class bit set and thus detection doesn’t trigger.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Mhjubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubjª)”}”(hŒWThe I2C driver usually detects devices, but your device lives at an unexpected address.”h]”h¸)”}”(hŒWThe I2C driver usually detects devices, but your device lives at an unexpected address.”h]”hŒWThe I2C driver usually detects devices, but your device lives at an unexpected address.”…””}”(hj*hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Mhj&ubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubjª)”}”(hŒÒThe I2C driver usually detects devices, but your device is not detected, either because the detection routine is too strict, or because your device is not officially supported yet but you know it is compatible.”h]”h¸)”}”(hŒÒThe I2C driver usually detects devices, but your device is not detected, either because the detection routine is too strict, or because your device is not officially supported yet but you know it is compatible.”h]”hŒÒThe I2C driver usually detects devices, but your device is not detected, either because the detection routine is too strict, or because your device is not officially supported yet but you know it is compatible.”…””}”(hjBhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Mhj>ubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubjª)”}”(hŒYYou are developing a driver on a test board, where you soldered the I2C device yourself. ”h]”h¸)”}”(hŒXYou are developing a driver on a test board, where you soldered the I2C device yourself.”h]”hŒXYou are developing a driver on a test board, where you soldered the I2C device yourself.”…””}”(hjZhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h MhjVubah}”(h]”h ]”h"]”h$]”h&]”uh1j©hj hžhhŸh¶h Nubeh}”(h]”h ]”h"]”h$]”h&]”jájâuh1j¤hŸh¶h Mhj\hžhubh¸)”}”(hX¬This interface is a replacement for the force_* module parameters some I2C drivers implement. Being implemented in i2c-core rather than in each device driver individually, it is much more efficient, and also has the advantage that you do not have to reload the driver to change a setting. You can also instantiate the device before the driver is loaded or even available, and you don't need to know what driver the device needs.”h]”hX®This interface is a replacement for the force_* module parameters some I2C drivers implement. Being implemented in i2c-core rather than in each device driver individually, it is much more efficient, and also has the advantage that you do not have to reload the driver to change a setting. You can also instantiate the device before the driver is loaded or even available, and you don’t need to know what driver the device needs.”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h M hj\hžhubeh}”(h]”Œ$method-4-instantiate-from-user-space”ah ]”h"]”Œ%method 4: instantiate from user-space”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kæubeh}”(h]”Œhow-to-instantiate-i2c-devices”ah ]”h"]”Œhow to instantiate i2c devices”ah$]”h&]”uh1h¡hhhžhhŸh¶h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h¶uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¦NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jµŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h¶Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jjŒjÛjØjYjVj€j}jÓjÐjtjqjYjVj‡j„uŒ nametypes”}”(j‰jÛ‰jY‰j€‰jÓ‰jt‰jY‰j‡‰uh}”(jŒh£jØhÇjVjj}j\jÐjƒjqjÞjVjwj„j\uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.