summaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core-base.c
Commit message (Collapse)AuthorAgeFilesLines
* i2c: add param sanity check to i2c_transfer()Ard Biesheuvel2018-04-111-0/+3
| | | | | | | | | | | The API docs describe i2c_transfer() as taking a pointer to an array of i2c_msg containing at least 1 entry, but leaves it to the individual drivers to sanity check the msgs and num parameters. Let's do this in core code instead. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [wsa: changed '<= 0' to '< 1'] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: Update i2c_trace_msg static key to modern apiDavidlohr Bueso2018-04-031-6/+7
| | | | | | | | | | | | | | No changes in refcount semantics -- key init is false; replace static_key_slow_inc|dec with static_branch_inc|dec static_key_false with static_branch_unlikely Added a '_key' suffix to i2c_trace_msg, for better self documentation. Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Reviewed-by: David Howells <dhowells@redhat.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: fix parameter of trace_i2c_resultAhbong Chang2018-04-031-1/+1
| | | | | | | | | | | According to the event i2c_result defined in include/trace/events/i2c.h, the second parameter should be the number of messages instead of the ended loop index. The value of ended loop index is the same as ret. Signed-off-by: Ahbong Chang <cwahbong@google.com> Reviewed-by: Todd Poynor <toddpoynor@google.com> Reviewed-by: David Howells <dhowells@redhat.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: make i2c_check_addr_validity() staticWolfram Sang2018-03-241-1/+1
| | | | | | | | After previous refactoring, there is only one user in the same file left. Make the function static now. [wsa: added 'int' to bare 'unsigned'] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* Merge branch 'i2c-mux/for-next' of https://github.com/peda-r/i2c-mux into ↵Wolfram Sang2018-03-171-0/+33
|\ | | | | | | | | | | | | i2c/for-4.17 "These patches verify the device id of the PCA984x mux chips using standardized (but rarely implemented) i2c device identification."
| * i2c: add i2c_get_device_id() to get the standard i2c device idPeter Rosin2018-03-061-0/+33
| | | | | | | | | | | | | | | | | | | | | | Can be used during probe to double check that the probed device is what is expected. Loosely based on code from Adrian Fiergolski <adrian.fiergolski@cern.ch>. Tested-by: Adrian Fiergolski <adrian.fiergolski@cern.ch> Reviewed-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Peter Rosin <peda@axentia.se>
* | i2c: core: report OF style module alias for devices registered via OFJavier Martinez Canillas2018-03-051-0/+8
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The buses should honor the firmware interface used to register the device, but the I2C core reports a MODALIAS of the form i2c:<device> even for I2C devices registered via OF. This means that user-space will never get an OF stype uevent MODALIAS even when the drivers modules contain aliases exported from both the I2C and OF device ID tables. For example, an Atmel maXTouch Touchscreen registered by a DT node with compatible "atmel,maxtouch" has the following module alias: $ cat /sys/class/i2c-adapter/i2c-8/8-004b/modalias i2c:maxtouch So udev won't be able to auto-load a module for an OF-only device driver. Many OF-only drivers duplicate the OF device ID table entries in an I2C ID table only has a workaround for how the I2C core reports the module alias. This patch changes the I2C core to report an OF related MODALIAS uevent if the device was registered via OF. So for the previous example, after this patch, the reported MODALIAS for the Atmel maXTouch will be the following: $ cat /sys/class/i2c-adapter/i2c-8/8-004b/modalias of:NtrackpadT<NULL>Catmel,maxtouch NOTE: This patch may break out-of-tree drivers that were relying on this behavior, and only had an I2C device ID table even when the device was registered via OF. There are no remaining drivers in mainline that do this, but out-of-tree drivers have to be fixed and define a proper OF device ID table to have module auto-loading working. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Tested-by: Dmitry Mastykin <mastichi@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* Merge branch 'i2c/for-4.16' of ↵Linus Torvalds2018-02-041-116/+96Star
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux Pull i2c updates from Wolfram Sang: "I2C has the following changes for you: - new flag to mark DMA safe buffers in i2c_msg. Also, some infrastructure around it. And docs. - huge refactoring of the at24 driver led by the new maintainer Bartosz - update I2C bus recovery to send STOP after recovery - conversion from gpio to gpiod for I2C bus recovery - adding a fault-injector to the i2c-gpio driver - lots of small driver improvements, and bigger ones to i2c-sh_mobile" * 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (99 commits) i2c: mv64xxx: Add myself as maintainer for this driver i2c: mv64xxx: Fix clock resource by adding an optional bus clock i2c: mv64xxx: Remove useless test before clk_disable_unprepare i2c: mxs: use true and false for boolean values i2c: meson: update doc description to fix build warnings i2c: meson: add configurable divider factors dt-bindings: i2c: update documentation for the Meson-AXG i2c: imx-lpi2c: add runtime pm support i2c: rcar: fix some trivial typos in comments i2c: davinci: fix the cpufreq transition i2c: rk3x: add proper kerneldoc header i2c: rk3x: account for const type of of_device_id.data i2c: acorn: remove outdated path from file header i2c: acorn: add MODULE_LICENSE tag i2c: rcar: implement bus recovery i2c: send STOP after successful bus recovery i2c: ensure SDA is released in recovery if SDA is controllable i2c: add 'set_sda' to bus_recovery_info i2c: add identifier in declarations for i2c_bus_recovery i2c: make kerneldoc about bus recovery more precise ...
| * i2c: send STOP after successful bus recoveryWolfram Sang2018-01-161-0/+12
| | | | | | | | | | | | | | | | | | If we managed to get a client release SDA again, send a STOP afterwards to make sure we have a consistent state on the bus again. Tested-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: ensure SDA is released in recovery if SDA is controllableWolfram Sang2018-01-161-0/+2
| | | | | | | | | | | | | | | | | | If we have a function to control SDA, we should ensure that SDA is not held down by us. So, release the GPIO in this case. Tested-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: add 'set_sda' to bus_recovery_infoWolfram Sang2018-01-161-1/+10
| | | | | | | | | | | | | | | | | | | | | | This will be needed when we want to create STOP conditions, too, later. Create the needed fields and populate them for the GPIO case if the GPIO is set to output. Tested-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: refactor i2c_master_{send_recv}Wolfram Sang2017-12-031-46/+18Star
| | | | | | | | | | | | | | | | | | | | | | | | | | Those two functions are very similar, the only differences are that one needs the I2C_M_RD flag for its message while the other one needs the buffer casted to drop the const. Introduce a generic helper which allows to specify the flags (also needed later for DMA safe variants of these calls) and let the casting be done in the inlining functions which are now calling the new helper function. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: add helpers to ease DMA handlingWolfram Sang2017-12-031-0/+46
| | | | | | | | | | | | | | | | | | | | One helper checks if DMA is suitable and optionally creates a bounce buffer, if not. The other function returns the bounce buffer and makes sure the data is properly copied back to the message. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: core: fix compile issue related to incorrect gpio headerPhil Reid2017-11-281-1/+1
| | | | | | | | | | | | | | | | | | | | The correct header to include for the gpiod interface is <linux/gpio/consumer.h>. Fixes: 3991c5c80beaf7eb9 ("i2c: Switch to using gpiod interface for gpio bus recovery") Signed-off-by: Phil Reid <preid@electromag.com.au> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: remove legacy integer scl/sda gpio for recoveryPhil Reid2017-11-271-76/+2Star
| | | | | | | | | | | | | | | | | | | | | | Remove all reference to code related to using integer based ids for scl/sda gpio for bus recovery. All in tree drivers are now using the gpio descriptors to specific the required gpios. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Phil Reid <preid@electromag.com.au> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
| * i2c: Switch to using gpiod interface for gpio bus recoveryPhil Reid2017-11-271-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently the i2c gpio recovery code uses gpio integer interface instead of the gpiod. This change switch the core code to use the gpiod while still retaining compatibility with the gpio integer interface. This will allow individual driver to be updated and tested individual to switch to using the gpiod interface. Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* | i2c: core: decrease reference count of device node in i2c_unregister_deviceLixin Wang2018-01-171-1/+5
|/ | | | | | | | | | | Reference count of device node was increased in of_i2c_register_device, but without decreasing it in i2c_unregister_device. Then the added device node will never be released. Fix this by adding the of_node_put. Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com> Tested-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Cc: stable@kernel.org
* i2c: Make i2c_unregister_device() NULL-awareAndy Shevchenko2017-11-021-2/+3
| | | | | | | It's a common pattern to be NULL-aware when freeing resources. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* Merge branch 'i2c/sbs-manager' into i2c/for-4.15Wolfram Sang2017-11-011-0/+9
|\
| * i2c: core: call of_i2c_setup_smbus_alert in i2c_register_adapterPhil Reid2017-10-281-0/+9
| | | | | | | | | | | | | | | | Add a call to of_i2c_setup_smbus_alert when a i2c adapter is registered so the the smbalert driver can be registered. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* | i2c: generic recovery: check SCL before SDAClaudio Foellmi2017-10-281-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Move the check for a stuck SCL before the check for a high SDA. This prevent false positives in the specific case that SDA is fine and SCL is stuck, which previously returned 0. Also check SDA again after the loop, if we can. Together, these changes should lead to a lot more failed recoveries being caught and returning error codes. Signed-off-by: Claudio Foellmi <claudio.foellmi@ergon.ch> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* | i2c: Allow overriding dev_name through board_infoHans de Goede2017-10-271-2/+8
|/ | | | | | | | | | | | | | | | | | | | | | | For devices not instantiated through ACPI the i2c-client's device-name gets set to <busnr>-<addr> by default, e.g. "0-0022" this means that the device-name is dependent on the order in which the i2c-busses are enumerated. In some cases having a predictable constant device-name is desirable, for example on non device-tree platforms the link between a regulator and its consumers is specified by the platform code by setting regulator_init_data.consumers. This array identifies the regulator's consumers by dev_name and supply(-name). Which requires a constant dev_name. This commit adds a dev_name field to i2c_board_info allowing platform code to set a contstant dev_name so that the device can be identified by its dev_name in other platform code. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Mark Brown <broonie@kernel.org> (live at ELCE17) Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> (live at ELCE17) Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: core: Make comment about I2C table requirement to reflect the codeJavier Martinez Canillas2017-08-141-2/+2
| | | | | | | | | | | | | | | | | | | | I2C drivers were required to have an I2C device ID table even if were for devices that would only be registered using a specific firmware interface (e.g: OF or ACPI). But commit da10c06a044b ("i2c: Make I2C ID tables non-mandatory for DT'ed devices") changed the I2C core to relax the requirement and allow drivers to avoid defining this table. Unfortunately it only took into account drivers for OF-only devices and forgot about ACPI-only ones, and this was fixed by commit c64ffff7a9d1 ("i2c: core: Allow empty id_table in ACPI case as well"). But the latter didn't update the original comment, so it doesn't reflect what the code does now. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: core: Allow empty id_table in ACPI case as wellAndy Shevchenko2017-07-311-0/+1
| | | | | | | | | | | | | | | | | | | For now empty ID table is not allowed with ACPI and prevents driver to be probed. Add a check to allow empty ID table. This introduces a helper i2c_acpi_match_device(). Note, we rename some static function in i2c-core-acpi.c to distinguish with public API. Fixes: da10c06a044b ("i2c: Make I2C ID tables non-mandatory for DT'ed devices") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Tested-by: Rajmohan Mani <rajmohan.mani@intel.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> [wsa: needed to get some drivers probed again] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: reformat core-base file headerWolfram Sang2017-05-311-21/+22
| | | | | | | | Finally, apply modern comment rules to the file header. The old style looked very non-Linuxish and challenged my eyes for some time now. I also added my own copyright for the period of me being the maintainer. Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: remove unneeded includes from coreWolfram Sang2017-05-311-2/+0Star
| | | | | | | | They seem like cruft to me. I couldn't find any evidence that something included from there is actually used. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: break out ACPI support into separate fileWolfram Sang2017-05-311-648/+0Star
| | | | | | | | | Removes some ifdeffery. Also add the new file to the relevant MAINTAINERS section. Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: break out OF support into separate fileWolfram Sang2017-05-311-264/+1Star
| | | | | | | Also removes some ifdeffery. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: break out smbus support into separate fileWolfram Sang2017-05-311-574/+0Star
| | | | | | | | | Break out the exported SMBus functions and the emulation layer into a separate file. This also involved splitting up the tracing header into an I2C and an SMBus part. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: break out slave support into separate fileWolfram Sang2017-05-311-101/+1Star
| | | | | | | Also removes some ifdeffery. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
* i2c: rename core source file to allow refactorizationWolfram Sang2017-05-311-0/+3831
The I2C core became quite huge and its monolithic structure makes maintenance hard. So, prepare to break out some functionality into separate files by renaming the source file. Note that we keep the resulting object name constant to avoid regressions. Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>