aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/eeprom/at24.c
AgeCommit message (Collapse)AuthorFilesLines
2018-03-23eeprom: at24: remove code separatorsBartosz Golaszewski1-4/+0
These are just two left-overs from times when this driver was bigger. They are not really useful anymore. Remove them. Signed-off-by: Bartosz Golaszewski <[email protected]> Tested-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-03-23eeprom: at24: arrange local variablesBartosz Golaszewski1-10/+16
Arrange declarations of local variables by line length as visually it's easier to read. Signed-off-by: Bartosz Golaszewski <[email protected]> Tested-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-03-23eeprom: at24: remove nvmem_config from at24_dataBartosz Golaszewski1-16/+16
This structure only needs to exist during the call to nvmem_register(). Signed-off-by: Bartosz Golaszewski <[email protected]> Tested-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-03-23eeprom: at24: disable regmap lockingBartosz Golaszewski1-0/+1
We use our own mutex for locking. Disable the regmap-specific locking. Signed-off-by: Bartosz Golaszewski <[email protected]> Tested-by: Andy Shevchenko <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2018-01-02eeprom: at24: extend the list of chips supported in DTBartosz Golaszewski1-0/+9
Add all supported at24 variants to the of_match table. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]>
2018-01-01eeprom: at24: add support for the write-protect pinBartosz Golaszewski1-0/+11
AT24 EEPROMs have a write-protect pin, which - when pulled high - inhibits writes to the upper quadrant of memory (although it has been observed that on some chips it disables writing to the entire memory range). On some boards, this pin is connected to a GPIO and pulled high by default, which forces the user to manually change its state before writing. On linux this means that we either need to hog the line all the time, or set the GPIO value before writing from outside of the at24 driver. Make the driver check if the write-protect GPIO was defined in the device tree and pull it low whenever writing to the EEPROM. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
2018-01-01eeprom: at24: remove temporary fix for at24mac402 sizeSven Van Asbroeck1-10/+0
The chip size passed via devicetree, i2c, or acpi device ids is now no longer limited to a power of two. So the temporary fix can be removed. Signed-off-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: convert magic numbers to structsSven Van Asbroeck1-121/+100
Fundamental properties such as capacity and page size differ among at24-type chips. But these chips do not have an id register, so this can't be discovered at runtime. Traditionally, at24-type eeprom properties were determined in two ways: - by passing a 'struct at24_platform_data' via platform_data, or - by naming the chip type in the devicetree, which passes a 'magic number' to probe(), which is then converted to a 'struct at24_platform_data'. Recently a bug was discovered because the magic number rounds down all chip sizes to the lowest power of two. This was addressed by a work-around commit 5478e478eee3 ("eeprom: at24: correctly set the size for at24mac402"), with the wish that magic numbers should over time be converted to structs. This patch replaces the magic numbers with 'struct at24_chip_data'. Signed-off-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: code shrinkBartosz Golaszewski1-17/+6
A regmap_config struct is pretty big and declaring two of them statically just to tweak the reg_bits value adds unnecessary bloat. Declare the regmap config locally in at24_probe() instead. Bloat-o-meter output for ARM: add/remove: 0/2 grow/shrink: 1/0 up/down: 4/-272 (-268) Function old new delta at24_probe 1560 1564 +4 regmap_config_8 136 - -136 regmap_config_16 136 - -136 Total: Before=7012, After=6744, chg -3.82% Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: use a common prefix for all symbols in at24.cBartosz Golaszewski1-16/+18
There are a couple symbols defined in the driver source file which are missing the at24_ prefix. This patch fixes that. For module params: use module_param_named() in order to not break userspace. Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: fix coding style issuesBartosz Golaszewski1-9/+9
Fix issues reported by checkpatch for at24.c. Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: support eeproms that do not auto-rollover readsSven Van Asbroeck1-12/+27
Some multi-address eeproms in the at24 family may not automatically roll-over reads to the next slave address. On those eeproms, reads that straddle slave boundaries will not work correctly. Solution: Mark such eeproms with a flag that prevents reads straddling slave boundaries. Add the AT24_FLAG_NO_RDROL flag to the eeprom entry in the device_id table, or add 'no-read-rollover' to the eeprom devicetree entry. Note that I have not personally enountered an at24 chip that does not support read rollovers. They may or may not exist. However, my hardware requires this functionality because of a quirk. Signed-off-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: remove now unneeded smbus-related codeHeiner Kallweit1-48/+8
Remove remaining now unneeded code dealing with SMBUS details. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: remove old read functionsHeiner Kallweit1-186/+0
Remove the old and now unused read functions. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: add regmap-based read functionHeiner Kallweit1-1/+56
Add regmap-based read function and instead of using three different read functions (standard, mac, serial) use just one and factor out the read offset adjustment for mac and serial to at24_adjust_read_offset. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: remove old write functionsHeiner Kallweit1-117/+0
Remove the old and now unused write functions. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: add regmap-based write functionHeiner Kallweit1-1/+26
Add a regmap-based write function. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: change at24_translate_offset return typeHeiner Kallweit1-10/+24
Change return type of at24_translate_offset to *at24_client to make member regmap accessible for subsequent patches of this series. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2018-01-01eeprom: at24: add basic regmap_i2c supportHeiner Kallweit1-13/+44
This patch adds basic regmap support to be used by subsequent patches of this series. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2017-12-06eeprom: at24: change nvmem stride to 1David Lechner1-1/+1
Trying to read the MAC address from an eeprom that has an offset that is not a multiple of 4 causes an error currently. Fix it by changing the nvmem stride to 1. Cc: [email protected] Signed-off-by: David Lechner <[email protected]> [Bartosz: tweaked the commit message] Signed-off-by: Bartosz Golaszewski <[email protected]>
2017-12-03eeprom: at24: fix I2C device selection for runtime PMSakari Ailus1-14/+10
The at24 driver creates dummy I2C devices to access offsets in the chip that are outside the area supported using a single I2C address. It is not meaningful to use runtime PM to such devices; the system firmware (ACPI) does not know about these devices nor runtime PM was enabled for them. Always use the real device instead of the dummy ones. Fixes: 98e8201039af ("eeprom: at24: enable runtime pm support") Signed-off-by: Sakari Ailus <[email protected]> Tested-by: Sven Van Asbroeck on a 24AA16/24LC16B <[email protected]> [Bartosz: rebased on top of previous fixes for 4.15, tweaked the commit message] [Sven: fixed Bartosz's rebase] Signed-off-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2017-11-29eeprom: at24: check at24_read/write argumentsHeiner Kallweit1-0/+6
So far we completely rely on the caller to provide valid arguments. To be on the safe side perform an own sanity check. Cc: [email protected] Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2017-11-29eeprom: at24: fix reading from 24MAC402/24MAC602Heiner Kallweit1-1/+2
Chip datasheet mentions that word addresses other than the actual start position of the MAC delivers undefined results. So fix this. Current implementation doesn't work due to this wrong offset. Cc: [email protected] Fixes: 0b813658c115 ("eeprom: at24: add support for at24mac series") Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
2017-11-29eeprom: at24: correctly set the size for at24mac402Bartosz Golaszewski1-0/+10
There's an ilog2() expansion in AT24_DEVICE_MAGIC() which rounds down the actual size of EUI-48 byte array in at24mac402 eeproms to 4 from 6, making it impossible to read it all. Fix it by manually adjusting the value in probe(). This patch contains a temporary fix that is suitable for stable branches. Eventually we'll probably remove the call to ilog2() while converting the magic values to actual structs. Cc: [email protected] Fixes: 0b813658c115 ("eeprom: at24: add support for at24mac series") Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
2017-11-05eeprom: at24: Add OF device ID tableJavier Martinez Canillas1-1/+70
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. To maintain backward compatibility with old Device Trees, only use the OF device ID table .data if the device was registered via OF and the OF node compatible matches an entry in the OF device ID table. Suggested-by: Wolfram Sang <[email protected]> Signed-off-by: Javier Martinez Canillas <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2017-10-17eeprom: at24: enable runtime pm supportDivagar Mohandass1-0/+37
Currently the device is kept in D0, there is an opportunity to save power by enabling runtime pm. Device can be daisy chained from PMIC and we can't rely on I2C core for auto resume/suspend. Driver will decide when to resume/suspend. Reviewed-by: Sakari Ailus <[email protected]> Signed-off-by: Divagar Mohandass <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2017-10-17eeprom: at24: add support to fetch eeprom device property "size"Divagar Mohandass1-0/+4
Obtain the size of the EEPROM chip from DT if the "size" property is specified for the device. Suggested-by: Andy Shevchenko <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Sakari Ailus <[email protected]> Signed-off-by: Divagar Mohandass <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2017-02-11misc: eeprom: at24: use device_property_*() functions instead of ↵Ben Gardner1-26/+19
of_get_property() Allow the at24 driver to get configuration information from both OF and ACPI by using the more generic device_property functions. This change was inspired by the at25.c driver. I have a custom board with a ST M24C02 EEPROM attached to an I2C bus. With the following ACPI construct, this patch instantiates a working instance of the driver. Device (EEP0) { Name (_HID, "PRP0001") Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"compatible", Package () {"st,24c02"}}, Package () {"pagesize", 16}, }, }) Name (_CRS, ResourceTemplate () { I2cSerialBus ( 0x0057, ControllerInitiated, 400000, AddressingMode7Bit, "\\_SB.PCI0.I2C3", 0x00, ResourceConsumer,,) }) } Signed-off-by: Ben Gardner <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-08-22eeprom: at24: check if the chip is functional in probe()Bartosz Golaszewski1-2/+13
The at24 driver doesn't check if the chip is functional in its probe function. This leads to instantiating devices that are not physically present. For example the cape EEPROMs for BeagleBone Black are defined in the device tree at four addresses on i2c2, but normally only one of them is present. If the userspace doesn't know the location in advance, it will need to check if reading the nvmem attributes fails to determine which EEPROM is actually there. Try to read a single byte in probe() and bail-out with -ENODEV if the read fails. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-18eeprom: at24: tweak the loop_until_timeout() macroBartosz Golaszewski1-4/+4
loop_until_timeout() replaced a do {} while loop in the at24 driver with a for loop which, under certain circumstances (such as heavy load or low value of the write_timeout argument), can lead to the code in the loop never being executed. Make sure that at least one iteration of the code enclosed within loop_until_timeout() is always executed. Suggested-by: Wolfram Sang <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: add support for at24mac seriesBartosz Golaszewski1-0/+42
Add a new read function to the at24 driver allowing to retrieve the factory-programmed mac address embedded in chips from the at24mac family. These chips can be instantiated similarily to the at24cs family, except that there's no way of having access to both the serial number and the mac address at the same time - the user must instantiate either an at24cs or at24mac device as both special memory areas are accessible on the same slave address. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: support reading the serial number for 24csxxBartosz Golaszewski1-2/+78
The chips from the at24cs family have two memory areas - a regular read-write block and a read-only area containing the serial number. The latter is visible on a different slave address (the address of the rw memory block + 0x08). In order to access both blocks the user needs to instantiate a regular at24c device for the rw block address and a corresponding at24cs device on the serial number block address. Add a function that allows to access the serial number and assign it to at24->read_func if the chip allows serial number read operations and the driver was passed the relevant flag for this device. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: split at24_eeprom_write() into specialized functionsBartosz Golaszewski1-43/+91
Split at24_eeprom_write() into three smaller functions - one for the i2c operations and two for the smbus extensions (separate routines for block and byte transfers). Assign them in at24_probe() depending on the bus capabilities. Also: in order to avoid duplications move code adjusting the count argument into a separate function and use it for i2c and smbus block writes (no need for a roll-over for byte writes as we're always writing one byte). Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: split at24_eeprom_read() into specialized functionsBartosz Golaszewski1-54/+71
Split at24_eeprom_read() into two smaller functions - one for the i2c operations and one for the smbus extensions. Assign them in at24_probe() depending on the bus capabilities. Also: in order to avoid duplications move the comments related to offset calculations above the at24_translate_offset() routine. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: hide the read/write loop behind a macroBartosz Golaszewski1-22/+20
Before splitting the read/write routines into smaller, more specialized functions, unduplicate some code in advance. Use a 'for' loop instead of 'do while' when waiting for the previous write to complete and hide it behind a macro. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: call read/write functions via function pointersBartosz Golaszewski1-2/+9
The first step in simplifying the read and write functions is to call them via function pointers stored in at24_data. When we eventually split the routines into smaller ones (depending on whether they use smbus or i2c operations) we'll simply assign them to said pointers instead of checking the flags at runtime every time we read/write. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: coding style fixesBartosz Golaszewski1-5/+5
Align the arguments in broken lines with the arguments list's opening brackets and make checkpatch.pl happy by converting 'unsigned' into 'unsigned int'. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: move at24_read() below at24_eeprom_write()Bartosz Golaszewski1-32/+32
In preparation for splitting at24_eeprom_write() & at24_eeprom_read() into smaller, specialized routines move at24_read() below, so that it won't be intertwined with the low-level EEPROM accessors. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-07-17eeprom: at24: improve the device_id table readabilityBartosz Golaszewski1-14/+14
As part of the preparation for introducing support for more chips, improve the readability of the device table by separating columns with tabs. Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-05-20Merge tag 'char-misc-4.7-rc1' of ↵Linus Torvalds1-81/+22
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc Pull char / misc driver updates from Greg KH: "Here's the big char and misc driver update for 4.7-rc1. Lots of different tiny driver subsystems have updates here with new drivers and functionality. Details in the shortlog. All have been in linux-next with no reported issues for a while" * tag 'char-misc-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (125 commits) mcb: Delete num_cells variable which is not required mcb: Fixed bar number assignment for the gdd mcb: Replace ioremap and request_region with the devm version mcb: Implement bus->dev.release callback mcb: export bus information via sysfs mcb: Correctly initialize the bus's device mei: bus: call mei_cl_read_start under device lock coresight: etb10: adjust read pointer only when needed coresight: configuring ETF in FIFO mode when acting as link coresight: tmc: implementing TMC-ETF AUX space API coresight: moving struct cs_buffers to header file coresight: tmc: keep track of memory width coresight: tmc: make sysFS and Perf mode mutually exclusive coresight: tmc: dump system memory content only when needed coresight: tmc: adding mode of operation for link/sinks coresight: tmc: getting rid of multiple read access coresight: tmc: allocating memory when needed coresight: tmc: making prepare/unprepare functions generic coresight: tmc: splitting driver in ETB/ETF and ETR components coresight: tmc: cleaning up header file ...
2016-05-01eeprom: at24: remove nvmem regmap dependencySrinivas Kandagatla1-81/+22
This patch moves to nvmem support in the driver to use callback instead of regmap. Signed-off-by: Srinivas Kandagatla <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2016-04-16eeprom: at24: replace msleep() with usleep_range()Bartosz Golaszewski1-4/+2
We cannot expect msleep(1) to actually sleep for a period shorter than 20 ms. Replace all calls to msleep() with usleep_range(). Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2016-04-16eeprom: at24: remove a reduntant ifBartosz Golaszewski1-3/+0
The second check for I2C_FUNC_I2C is reduntant, so remove it. Signed-off-by: Bartosz Golaszewski <[email protected]> [wsa: reworded commit message] Signed-off-by: Wolfram Sang <[email protected]>
2016-03-01misc: at24: replace memory_accessor with nvmem_device_readAndrew Lunn1-30/+1
Now that the AT24 uses the NVMEM framework, replace the memory_accessor in the setup() callback with nvmem API calls. Signed-off-by: Andrew Lunn <[email protected]> Acked-by: Srinivas Kandagatla <[email protected]> Tested-by: Sekhar Nori <[email protected]> Acked-by: Wolfram Sang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2016-03-01eeprom: at24: extend driver to plug into the NVMEM frameworkAndrew Lunn1-41/+80
Add a regmap for accessing the EEPROM, and then use that with the NVMEM framework. Set the NVMEM config structure to enable backward, so that the 'eeprom' file in sys is provided by the framework. Signed-off-by: Andrew Lunn <[email protected]> Acked-by: Srinivas Kandagatla <[email protected]> Tested-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2016-02-07misc: eeprom: use kobj_to_dev()Geliang Tang1-2/+2
Use kobj_to_dev() instead of open-coding it. Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
2015-10-26at24: enable ACPI device found on Galileo Gen2Andy Shevchenko1-3/+19
There is a 24c08 chip connected to i2c bus on Intel Galileo Gen2 board. Enable it via ACPI ID INT3499. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2015-08-24eeprom: at24: use i2c_smbus_read_i2c_block_data_or_emulatedIrina Tirdea1-31/+6
For i2c busses that support only SMBUS extensions, the eeprom at24 driver reads data from the device using the SMBus block, word or byte read protocols depending on availability. Replace the block read emulation from the driver with the i2c_smbus_read_i2c_block_data_or_emulated call from i2c core. Signed-off-by: Irina Tirdea <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2015-08-10misc: Drop owner assignment from i2c_driverKrzysztof Kozlowski1-1/+0
i2c_driver does not need to set an owner because i2c_register_driver() will set it. Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
2015-07-31misc: eeprom: at24: clean up at24_bin_write()Vladimir Zapolskiy1-3/+0
The change removes redundant sysfs binary file boundary check, since this task is already done on caller side in fs/sysfs/file.c Signed-off-by: Vladimir Zapolskiy <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>