Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: eeprom_93xx46: Implement eeprom_93xx46 DT bindings.

This commit implements bindings in the eeprom_93xx46 driver allowing
device word size and read-only attributes to be specified via
devicetree.

Signed-off-by: Cory Tusar <cory.tusar@pid1solutions.com>
Tested-by: Chris Healy <chris.healy@zii.aero>
Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Cory Tusar and committed by
Greg Kroah-Hartman
c074abe0 862a4a78

+49
+49
drivers/misc/eeprom/eeprom_93xx46.c
··· 13 13 #include <linux/kernel.h> 14 14 #include <linux/module.h> 15 15 #include <linux/mutex.h> 16 + #include <linux/of.h> 17 + #include <linux/of_device.h> 16 18 #include <linux/slab.h> 17 19 #include <linux/spi/spi.h> 18 20 #include <linux/sysfs.h> ··· 296 294 } 297 295 static DEVICE_ATTR(erase, S_IWUSR, NULL, eeprom_93xx46_store_erase); 298 296 297 + static const struct of_device_id eeprom_93xx46_of_table[] = { 298 + { .compatible = "eeprom-93xx46", }, 299 + {} 300 + }; 301 + MODULE_DEVICE_TABLE(of, eeprom_93xx46_of_table); 302 + 303 + static int eeprom_93xx46_probe_dt(struct spi_device *spi) 304 + { 305 + struct device_node *np = spi->dev.of_node; 306 + struct eeprom_93xx46_platform_data *pd; 307 + u32 tmp; 308 + int ret; 309 + 310 + pd = devm_kzalloc(&spi->dev, sizeof(*pd), GFP_KERNEL); 311 + if (!pd) 312 + return -ENOMEM; 313 + 314 + ret = of_property_read_u32(np, "data-size", &tmp); 315 + if (ret < 0) { 316 + dev_err(&spi->dev, "data-size property not found\n"); 317 + return ret; 318 + } 319 + 320 + if (tmp == 8) { 321 + pd->flags |= EE_ADDR8; 322 + } else if (tmp == 16) { 323 + pd->flags |= EE_ADDR16; 324 + } else { 325 + dev_err(&spi->dev, "invalid data-size (%d)\n", tmp); 326 + return -EINVAL; 327 + } 328 + 329 + if (of_property_read_bool(np, "read-only")) 330 + pd->flags |= EE_READONLY; 331 + 332 + spi->dev.platform_data = pd; 333 + 334 + return 0; 335 + } 336 + 299 337 static int eeprom_93xx46_probe(struct spi_device *spi) 300 338 { 301 339 struct eeprom_93xx46_platform_data *pd; 302 340 struct eeprom_93xx46_dev *edev; 303 341 int err; 342 + 343 + if (spi->dev.of_node) { 344 + err = eeprom_93xx46_probe_dt(spi); 345 + if (err < 0) 346 + return err; 347 + } 304 348 305 349 pd = spi->dev.platform_data; 306 350 if (!pd) { ··· 418 370 static struct spi_driver eeprom_93xx46_driver = { 419 371 .driver = { 420 372 .name = "93xx46", 373 + .of_match_table = of_match_ptr(eeprom_93xx46_of_table), 421 374 }, 422 375 .probe = eeprom_93xx46_probe, 423 376 .remove = eeprom_93xx46_remove,