aboutsummaryrefslogtreecommitdiff
path: root/drivers/i2c/i2c-core.c
AgeCommit message (Collapse)Author
2008-07-21Driver Core: add ability for class_for_each_device to start in middle of listGreg Kroah-Hartman
This mirrors the functionality that driver_for_each_device has as well. We add a start variable, and all callers of the function are fixed up at the same time. The block layer will be using this new functionality in a follow-on patch. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-07-16i2c: Clear i2c_adapter.dev on adapter removalJean Delvare
Clear i2c_adapter.dev on adapter removal. This makes it possible to re-add the adapter at a later point, which some drivers (i2c-amd756-s4882, i2c-nforce2-s4985) actually do. This fixes a bug reported by John Stultz here: http://lkml.org/lkml/2008/7/15/720 and by Ingo Molar there: http://lkml.org/lkml/2008/7/16/78 Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: John Stultz <johnstul@us.ibm.com> Cc: Ingo Molnar <mingo@elte.hu>
2008-07-14i2c: Add detection capability to new-style driversJean Delvare
Add a mechanism to let new-style i2c drivers optionally autodetect devices they would support on selected buses and ask i2c-core to instantiate them. This is a replacement for legacy i2c drivers, much cleaner. Where drivers had to implement both a legacy i2c_driver and a new-style i2c_driver so far, this mechanism makes it possible to get rid of the legacy i2c_driver and implement both enumerated and detected device support with just one (new-style) i2c_driver. Here is a quick conversion guide for these drivers, step by step: * Delete the legacy driver definition, registration and removal. Delete the attach_adapter and detach_client methods of the legacy driver. * Change the prototype of the legacy detect function from static int foo_detect(struct i2c_adapter *adapter, int address, int kind); to static int foo_detect(struct i2c_client *client, int kind, struct i2c_board_info *info); * Set the new-style driver detect callback to this new function, and set its address_data to &addr_data (addr_data is generally provided by I2C_CLIENT_INSMOD.) * Add the appropriate class to the new-style driver. This is typically the class the legacy attach_adapter method was checking for. Class checking is now mandatory (done by i2c-core.) See <linux/i2c.h> for the list of available classes. * Remove the i2c_client allocation and freeing from the detect function. A pre-allocated client is now handed to you by i2c-core, and is freed automatically. * Make the detect function fill the type field of the i2c_board_info structure it was passed as a parameter, and return 0, on success. If the detection fails, return -ENODEV. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Call client_unregister for new-style devices tooJean Delvare
We call adapter->client_register for both legacy and new-style i2c devices, however we only call adapter->client_unregister for legacy drivers. This doesn't make much sense. Usually, drivers will undo in client_unregister what they did in client_register, so we should call neither or both for every given i2c device. In order to ease the transition from legacy to new-style devices, it seems preferable to actually call both. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
2008-07-14i2c: Export the i2c_bus_type symbolJon Smirl
Export the root of the i2c bus so that PowerPC device tree code can iterate over devices on the i2c bus. Signed-off-by: Jon Smirl <jonsmirl@gmail.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Simplify i2c_device_probeJean Delvare
i2c_driver.id_table is mandatory now, so we can simplify i2c_device_probe() a bit. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Simplify i2c_del_driver()Jean Delvare
i2c_del_driver() can be simplified a bit. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Use list_for_each_entry_safeMatthias Kaehlcke
Use list_for_each_entry_safe() in i2c_del_adapter() and i2c_del_driver(). Signed-off-by: Matthias Kaehlcke <matthias@kaehlcke.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: i2c_use_client() defends against NULLDavid Brownell
Defend the i2c refcount calls against NULL pointers, as is important (and conventional) for such calls. Note that none of the current callers of i2c_use_client() use its return value. [JD: I hate this but apparently all the other subsystems do it so...] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Kerneldoc for most I/O callsDavid Brownell
Provide kerneldoc for most of the I2C and SMBus I/O calls. Add a comment summarizing some fault reporting issues which affect the ability to provide clean fault reports through I2C master transfer calls. (Making it hard to precisely specify their return values...) Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Delete unused function i2c_smbus_write_quickJean Delvare
Function i2c_smbus_write_quick has no users left, so we can delete it. Also update the list of these helper functions which are gone but could be added back if needed. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c-core: Return -Errno, not -1David Brownell
More updates to the I2C stack's fault reporting: make the core stop returning "-1" (usually "-EPERM") for all faults. Instead, pass lower level fault code up the stack, or return some appropriate errno. This patch happens to touch almost exclusively SMBus calls. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c-core: Remove needless includeJean Delvare
i2c-core doesn't use seq files, so doesn't need to include <linux/seq_file.h>. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-07-14i2c: Use class_for_each_deviceDave Young
Use class_for_each_device for iteration. Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-05-18i2c: Kill the old driver matching schemeJean Delvare
Remove the old driver_name/type scheme for i2c driver matching. Only the standard aliasing model will be used from now on. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-05-11i2c: Match dummy devices by typeJean Delvare
As the old driver_name/type matching scheme is going away soon, change the dummy device mechanism to use the new matching scheme. This has the downside that dummy i2c clients can no longer choose their name, they'll all appear as "dummy" in sysfs and in log messages. I don't think it is a problem in practice though, as there is little reason to use these i2c clients to log messages. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-04-29i2c: Add support for device alias namesJean Delvare
Based on earlier work by Jon Smirl and Jochen Friedrich. This patch allows new-style i2c chip drivers to have alias names using the official kernel aliasing system and MODULE_DEVICE_TABLE(). At this point, the old i2c driver binding scheme (driver_name/type) is still supported. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Jochen Friedrich <jochen@scram.de> Cc: Jon Smirl <jonsmirl@gmail.com> Cc: Kay Sievers <kay.sievers@vrfy.org>
2008-04-22i2c: Replace remaining __FUNCTION__ occurrencesHarvey Harrison
__FUNCTION__ is gcc-specific, use __func__. Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-04-18Convert asm/semaphore.h users to linux/semaphore.hMatthew Wilcox
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
2008-03-23i2c: Fix docbook problemRandy Dunlap
Sometimes kernel-doc and xmlto conspire to create output that is invalid and causes problems. Until I know a real/better solution, change the source code that causes this. If anyone has better fixes or can just explain what is happening here, that would be great. xmlto: input does not validate (status 1) mmotm-2008-0314-1449/Documentation/DocBook/kernel-api.xml:71468: parser error : Opening and ending tag mismatch: programlisting line 71464 and para </para><para> ^ mmotm-2008-0314-1449/Documentation/DocBook/kernel-api.xml:71480: parser error : Opening and ending tag mismatch: para line 71473 and programlisting </programlisting></informalexample> ^ make[1]: *** [Documentation/DocBook/kernel-api.html] Error 1 Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-03-12i2c: Keep client->driver and client->dev.driver in syncHans Verkuil
Ensure that client->driver is set to NULL if the probe() returns an error (this keeps client->driver and client->dev.driver in sync). Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Add i2c_new_dummy() utilityDavid Brownell
This adds a i2c_new_dummy() primitive to help work with devices that consume multiple addresses, which include many I2C eeproms and at least one RTC. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Drop legacy locking in i2c_new_probed_deviceJean Delvare
It is no longer required to hold adapter->clist_lock to call i2c_check_addr. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
2008-01-27i2c: Limit locking scope in i2c_detach_clientJean Delvare
We only need to hold adapter->clist_lock when we touch the client list. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c-remove-redundant-i2c_client-list.patchDavid Brownell
This goes on top of the patch removing most i2c_adapter.clients usage, updating i2c_attach_client: - Don't call device_register() while holding clist_lock. This removes a self-deadlock when on the i2c_driver.probe() path, for drivers that need to attach new devices (e.g. dummies). - Remove a redundant address check. The driver model core does this as a consequence of guaranteeing unique names. - Move the "device registered" diagnostic so that it never lies; previously, on error paths it would falsely report success. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Stop using the redundant client listDavid Brownell
The i2c_adapter.clients list of i2c_client nodes duplicates driver model state. This patch starts removing that list, letting us remove most existing users of those i2c-core lists. * The core I2C code now iterates over the driver model's list instead of the i2c-internal one in some places where it's safe: - Passing a command/ioctl to each client, a mechanims used almost exclusively by DVB adapters; - Device address checking, in both i2c-core and i2c-dev. * Provide i2c_verify_client() to use with driver model iterators. * Flag the relevant i2c_adapter and i2c_client fields as deprecated, to help prevent new users from appearing. For the moment the list needs to stick around, since some issues show up when deleting devices created by legacy I2C drivers. (They don't follow standard driver model rules. Removing those devices can cause self-deadlocks.) Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Support i2c_transfer in atomic contextsMike Rapoport
Allow i2c_transfer to be called in contexts where sleeping is not allowed. It is the reponsability of the caller to ensure that the underlying i2c bus driver will not sleep either. Signed-off-by: Mike Rapoport <mike@compulab.co.il> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Rename main mutexJean Delvare
Rename the main mutex in i2c-core from core_lists to core_lock. This makes more sense now that the redundant lists are gone. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2008-01-27i2c: Drop redundant i2c_driver.listJean Delvare
i2c_driver.list is superfluous, this list duplicates the one maintained by the driver core. Drop it. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: David Brownell <dbrownell@users.sourceforge.net>
2008-01-27i2c: Drop redundant i2c_adapter.listJean Delvare
i2c_adapter.list is superfluous, this list duplicates the one maintained by the driver core. Drop it. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: David Brownell <dbrownell@users.sourceforge.net>
2008-01-27i2c: Change prototypes of refcounting functionsJean Delvare
Use more standard prototypes for i2c_use_client() and i2c_release_client(). The former now returns a pointer to the client, and the latter no longer returns anything. This matches what all other subsystems do. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
2008-01-27i2c: Use the driver model reference countingJean Delvare
Don't implement our own reference counting mechanism for i2c clients when the driver model already has one. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
2008-01-27i2c: Constify client address dataMark M. Hoffman
This patch allows much of the I2C client address data to move from initdata into text. Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-11-15i2c: Make i2c_check_addr staticJean Delvare
i2c_check_addr is only used inside i2c-core now, so we can make it static and stop exporting it. Thanks to David Brownell for noticing. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-10-19Convert files to UTF-8 and some cleanupsJan Engelhardt
* Convert files to UTF-8. * Also correct some people's names (one example is Eißfeldt, which was found in a source file. Given that the author used an ß at all in a source file indicates that the real name has in fact a 'ß' and not an 'ss', which is commonly used as a substitute for 'ß' when limited to 7bit.) * Correct town names (Goettingen -> Göttingen) * Update Eberhard Mönkeberg's address (http://lkml.org/lkml/2007/1/8/313) Signed-off-by: Jan Engelhardt <jengelh@gmx.de> Signed-off-by: Adrian Bunk <bunk@kernel.org>
2007-10-13i2c: Remove i2c_algorithm.algo_control()David Brownell
This removes: - An effectively unused hook: i2c_algorithm.algo_control. - The i2c_control() call, used only by i2c-dev to call that unused hook or set two barely supported adapter params. (That param setting moves into i2c-dev.c ... still iffy due to lack of locking, but no other changes.) As shown by diffstat, this is a net code shrink. It also reduces the complexity of the I2C adapter and /dev interfaces. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-10-13i2c: Document struct i2c_msgDavid Brownell
Clarify use of the I2C_M_* flags by highlighting the fact that most of them depend on I2C_FUNC_PROTOCOL_MANGLING. Also provide kerneldoc for i2c_smbus_read_block_data() and also for "struct i2c_msg". Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-10-13i2c-core: Make some code staticAdrian Bunk
After the i2c-isa removal some code can become static. Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-10-13i2c: New-style devices can support driver model wakeup flagsDavid Brownell
We need to be able to flag I2C devices, such as RTCs, which can issue wake events (usually through IRQ lines). This adds an i2c_board_info.flags bit, and uses it to initialize the i2c device node. (And shrinks a few lines that were overly long.) Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-10-12Driver core: change add_uevent_var to use a structKay Sievers
This changes the uevent buffer functions to use a struct instead of a long list of parameters. It does no longer require the caller to do the proper buffer termination and size accounting, which is currently wrong in some places. It fixes a known bug where parts of the uevent environment are overwritten because of wrong index calculations. Many thanks to Mathieu Desnoyers for finding bugs and improving the error handling. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2007-07-19Merge branch 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6Linus Torvalds
* 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6: (44 commits) i2c: Delete the i2c-isa pseudo bus driver hwmon: refuse to load abituguru driver on non-Abit boards hwmon: fix Abit Uguru3 driver detection on some motherboards hwmon/w83627ehf: Be quiet when no chip is found hwmon/w83627ehf: No need to initialize fan_min hwmon/w83627ehf: Export the thermal sensor types hwmon/w83627ehf: Enable VBAT monitoring hwmon/w83627ehf: Add support for the VID inputs hwmon/w83627ehf: Fix timing issues hwmon/w83627ehf: Add error messages for two error cases hwmon/w83627ehf: Convert to a platform driver hwmon/w83627ehf: Update the Kconfig entry make coretemp_device_remove() static hwmon: Add LM93 support hwmon: Improve the pwmN_enable documentation hwmon/smsc47b397: Don't report missing fans as spinning at 82 RPM hwmon: Add support for newer uGuru's hwmon/f71805f: Add temperature-tracking fan control mode hwmon/w83627ehf: Preserve speed reading when changing fan min hwmon: fix detection of abituguru volt inputs ... Manual fixup of trivial conflict in MAINTAINERS file
2007-07-19i2c: Delete the i2c-isa pseudo bus driverJean Delvare
There are no users of i2c-isa left, so we can finally get rid of it. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-07-12i2c: Fix the i2c_smbus_read_i2c_block_data() prototypeJean Delvare
Let the drivers specify how many bytes they want to read with i2c_smbus_read_i2c_block_data(). So far, the block count was hard-coded to I2C_SMBUS_BLOCK_MAX (32), which did not make much sense. Many driver authors complained about this before, and I believe it's about time to fix it. Right now, authors have to do technically stupid things, such as individual byte reads or full-fledged I2C messaging, to work around the problem. We do not want to encourage that. I even found that some bus drivers (e.g. i2c-amd8111) already implemented I2C block read the "right" way, that is, they didn't follow the old, broken standard. The fact that it was never noticed before just shows how little i2c_smbus_read_i2c_block_data() was used, which isn't that surprising given how broken its prototype was so far. There are some obvious compatiblity considerations: * This changes the i2c_smbus_read_i2c_block_data() prototype. Users outside the kernel tree will notice at compilation time, and will have to update their code. * User-space has access to i2c_smbus_xfer() directly using i2c-dev, so the changed expectations would affect tools such as i2cdump. In order to preserve binary compatibility, we give I2C_SMBUS_I2C_BLOCK_DATA a new numeric value, and define I2C_SMBUS_I2C_BLOCK_BROKEN with the old numeric value. When i2c-dev receives a transaction with the old value, it can convert it to the new format on the fly. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-07-12i2c: Add kernel documentationDavid Brownell
Generate I2C kerneldoc; fix various glitches and add "context" sections to that documentation. Most I2C and SMBus functions still have no kerneldoc. Let me suggest providing kerneldoc for all the i2c_smbus_*() functions as a small and mostly self-contained project for anyone so inclined. :) Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-22i2c: Legacy i2c drivers shouldn't issue ueventsDavid Brownell
Prevent legacy drivers from issuing uevents for device creation/removal, so that userspace can't cause modprobing loops for them. This became a problem for some legacy PC drivers. I can't easily see it becoming an issue with I2C legacy drivers, but consistency-in-paranoia seems likely to be a good thing here. For usable i2c-level driver model uevents, just switch to a new-style driver. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01i2c: Restore i2c_smbus_read_block_dataJean Delvare
Add back the i2c_smbus_read_block_data helper function, it is needed by the upcoming lm93 hardware monitoring driver and possibly others. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01i2c: Make i2c_del_driver a void functionJean Delvare
Make i2c_del_driver a void function, like all other driver removal functions. It always returned 0 even when errors occured, and nobody ever actually checked the return value anyway. And we cannot fail a module removal anyway. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01i2c: Add i2c_new_probed_device()Jean Delvare
Add a new helper function to instantiate an i2c device. It is meant as a replacement for i2c_new_device() when you don't know for sure at which address your I2C/SMBus device lives. This happens frequently on TV adapters for example, you know there is a tuner chip on the bus, but depending on the exact board model and revision, it can live at different addresses. So, the new i2c_new_probed_device() function will probe the bus according to a list of addresses, and as soon as one of these addresses responds, it will call i2c_new_device() on that one address. This function will make it possible to port the old i2c drivers to the new model quickly. Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01i2c: i2c EXPORT_SYMBOL cleanupDavid Brownell
Make i2c-core.c obey Documentation/CodingStyle better by snugging the EXPORT_SYMBOL declarations next to the relevant definitions. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-01i2c: Add i2c_add_numbered_adapter()David Brownell
This adds a call, i2c_add_numbered_adapter(), registering an I2C adapter with a specific bus number and then creating I2C device nodes for any pre-declared devices on that bus. It builds on previous patches adding I2C probe() and remove() support, and that pre-declaration of devices. This completes the core support for "new style" I2C device drivers. Those follow the standard driver model for binding devices to drivers (using probe and remove methods) rather than a legacy model (where the driver tries to autoconfigure each bus, and registers devices itself). Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>