€•:Œ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Œ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:”…””}”(hhø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¸)”}”(hjh]”hŒparent”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubj)”}”(hŒname”h]”h¸)”}”(hj,h]”hŒname”…””}”(hj.hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khj*ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubj)”}”(hŒbus_id”h]”h¸)”}”(hjCh]”hŒbus_id”…””}”(hjEhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhjAubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubj)”}”(hŒbus ”h]”h¸)”}”(hŒbus”h]”hŒbus”…””}”(hj\hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KhjXubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubeh}”(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&]”höh÷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::”…””}”(hj1hž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);”…””}”hj?sbah}”(h]”h ]”h"]”h$]”h&]”höh÷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::”…””}”(hjMhž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);”…””}”hj[sbah}”(h]”h ]”h"]”h$]”h&]”höh÷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:”…””}”(hjihž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, };”…””}”hjwsbah}”(h]”h ]”h"]”h$]”h&]”höh÷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&]”höh÷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&]”höh÷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”}”(jôjñjÉjÆjìjéuŒ nametypes”}”(jô‰jɉjì‰uh}”(jñh£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.