€•´;Œ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”Œ2/translations/zh_CN/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/zh_TW/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/it_IT/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/ja_JP/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/ko_KR/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/pt_BR/driver-api/driver-model/device”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ2/translations/sp_SP/driver-api/driver-model/device”Œ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ŒThe Basic Device Structure”h]”hŒThe Basic Device Structure”…”�”}”(hh¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhh·h²hh³ŒL/var/lib/git/docbuild/linux/Documentation/driver-api/driver-model/device.rst”h´KubhŒ paragraph”“”)�”}”(hŒ(See the kerneldoc for the struct device.”h]”hŒ(See the kerneldoc for the struct device.”…”�”}”(hhÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khh·h²hubh¶)�”}”(hhh]”(h»)�”}”(hŒProgramming Interface”h]”hŒProgramming Interface”…”�”}”(hhÞh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhhÛh²hh³hÊh´K ubhÌ)�”}”(hŒYThe bus driver that discovers the device uses this to register the device with the core::”h]”hŒXThe bus driver that discovers the device uses this to register the device with the core:”…”�”}”(hhìh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K hhÛh²hubhŒ literal_block”“”)�”}”(hŒ)int device_register(struct device * dev);”h]”hŒ)int device_register(struct device * dev);”…”�”}”hhüsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1húh³hÊh´K hhÛh²hubhÌ)�”}”(hŒ/The bus should initialize the following fields:”h]”hŒ/The bus should initialize the following fields:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhhÛh²hubhŒ block_quote”“”)�”}”(hŒ- parent - name - bus_id - bus ”h]”hŒ bullet_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hŒparent”h]”hÌ)�”}”(hj)h]”hŒparent”…”�”}”(hj+h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khj'ubah}”(h]”h ]”h"]”h$]”h&]”uh1j%hj"ubj&)�”}”(hŒname”h]”hÌ)�”}”(hj@h]”hŒname”…”�”}”(hjBh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khj>ubah}”(h]”h ]”h"]”h$]”h&]”uh1j%hj"ubj&)�”}”(hŒbus_id”h]”hÌ)�”}”(hjWh]”hŒbus_id”…”�”}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhjUubah}”(h]”h ]”h"]”h$]”h&]”uh1j%hj"ubj&)�”}”(hŒbus ”h]”hÌ)�”}”(hŒbus”h]”hŒbus”…”�”}”(hjph²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khjlubah}”(h]”h ]”h"]”h$]”h&]”uh1j%hj"ubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1j h³hÊh´Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1jh³hÊh´KhhÛh²hubhÌ)�”}”(hŒqA device is removed from the core when its reference count goes to 0. The reference count can be adjusted using::”h]”hŒpA device is removed from the core when its reference count goes to 0. The reference count can be adjusted using:”…”�”}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhhÛh²hubhû)�”}”(hŒVstruct device * get_device(struct device * dev); void put_device(struct device * dev);”h]”hŒVstruct device * get_device(struct device * dev); void put_device(struct device * dev);”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´KhhÛh²hubhÌ)�”}”(hŒ™get_device() will return a pointer to the struct device passed to it if the reference is not already 0 (if it's in the process of being removed already).”h]”hŒ›get_device() will return a pointer to the struct device passed to it if the reference is not already 0 (if it’s in the process of being removed already).”…”�”}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KhhÛh²hubhÌ)�”}”(hŒhjàh²hubhÌ)�”}”(hŒ Example:::”h]”hŒ Example::”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K@hjàh²hubhû)�”}”(hŒjstatic DEVICE_ATTR(type, 0444, type_show, NULL); static DEVICE_ATTR(power, 0644, power_show, power_store);”h]”hŒjstatic DEVICE_ATTR(type, 0444, type_show, NULL); static DEVICE_ATTR(power, 0644, power_show, power_store);”…”�”}”hjSsbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´KBhjàh²hubhÌ)�”}”(hŒdHelper macros are available for common values of mode, so the above examples can be simplified to:::”h]”hŒcHelper macros are available for common values of mode, so the above examples can be simplified to::”…”�”}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KEhjàh²hubhû)�”}”(hŒ:static DEVICE_ATTR_RO(type); static DEVICE_ATTR_RW(power);”h]”hŒ:static DEVICE_ATTR_RO(type); static DEVICE_ATTR_RW(power);”…”�”}”hjosbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´KHhjàh²hubhÌ)�”}”(hŒ¸This declares two structures of type struct device_attribute with respective names 'dev_attr_type' and 'dev_attr_power'. These two attributes can be organized as follows into a group::”h]”hŒ¿This declares two structures of type struct device_attribute with respective names ‘dev_attr_type’ and ‘dev_attr_power’. These two attributes can be organized as follows into a group:”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KKhjàh²hubhû)�”}”(hXstatic struct attribute *dev_attrs[] = { &dev_attr_type.attr, &dev_attr_power.attr, NULL, }; static struct attribute_group dev_group = { .attrs = dev_attrs, }; static const struct attribute_group *dev_groups[] = { &dev_group, NULL, };”h]”hXstatic struct attribute *dev_attrs[] = { &dev_attr_type.attr, &dev_attr_power.attr, NULL, }; static struct attribute_group dev_group = { .attrs = dev_attrs, }; static const struct attribute_group *dev_groups[] = { &dev_group, NULL, };”…”�”}”hj‹sbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´KOhjàh²hubhÌ)�”}”(hŒwA helper macro is available for the common case of a single group, so the above two structures can be declared using:::”h]”hŒvA helper macro is available for the common case of a single group, so the above two structures can be declared using::”…”�”}”(hj™h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K^hjàh²hubhû)�”}”(hŒATTRIBUTE_GROUPS(dev);”h]”hŒATTRIBUTE_GROUPS(dev);”…”�”}”hj§sbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´Kahjàh²hubhÌ)�”}”(hŒ�This array of groups can then be associated with a device by setting the group pointer in struct device before device_register() is invoked::”h]”hŒŒThis array of groups can then be associated with a device by setting the group pointer in struct device before device_register() is invoked:”…”�”}”(hjµh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kchjàh²hubhû)�”}”(hŒ/dev->groups = dev_groups; device_register(dev);”h]”hŒ/dev->groups = dev_groups; device_register(dev);”…”�”}”hjÃsbah}”(h]”h ]”h"]”h$]”h&]”j j uh1húh³hÊh´Kfhjàh²hubhÌ)�”}”(hŒ¸The device_register() function will use the 'groups' pointer to create the device attributes and the device_unregister() function will use this pointer to remove the device attributes.”h]”hŒ¼The device_register() function will use the ‘groups’ pointer to create the device attributes and the device_unregister() function will use this pointer to remove the device attributes.”…”�”}”(hjÑh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kihjàh²hubhÌ)�”}”(hXÖWord of warning: While the kernel allows device_create_file() and device_remove_file() to be called on a device at any time, userspace has strict expectations on when attributes get created. When a new device is registered in the kernel, a uevent is generated to notify userspace (like udev) that a new device is available. If attributes are added after the device is registered, then userspace won't get notified and userspace will not know about the new attributes.”h]”hXØWord of warning: While the kernel allows device_create_file() and device_remove_file() to be called on a device at any time, userspace has strict expectations on when attributes get created. When a new device is registered in the kernel, a uevent is generated to notify userspace (like udev) that a new device is available. If attributes are added after the device is registered, then userspace won’t get notified and userspace will not know about the new attributes.”…”�”}”(hjßh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kmhjàh²hubhÌ)�”}”(hX This is important for device driver that need to publish additional attributes for a device at driver probe time. If the device driver simply calls device_create_file() on the device structure passed to it, then userspace will never be notified of the new attributes.”h]”hX This is important for device driver that need to publish additional attributes for a device at driver probe time. If the device driver simply calls device_create_file() on the device structure passed to it, then userspace will never be notified of the new attributes.”…”�”}”(hjíh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Kuhjàh²hubeh}”(h]”Œ attributes”ah ]”h"]”Œ attributes”ah$]”h&]”uh1hµhh·h²hh³hÊh´K'ubeh}”(h]”Œthe-basic-device-structure”ah ]”h"]”Œthe basic device structure”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”}”(jjjÝjÚjjýuŒ nametypes”}”(j‰j݉j‰uh}”(jh·jÚhÛjý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.