gpio-max7300.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2009 Wolfram Sang, Pengutronix
  4. *
  5. * Check max730x.c for further details.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/mutex.h>
  11. #include <linux/i2c.h>
  12. #include <linux/spi/max7301.h>
  13. #include <linux/slab.h>
  14. static int max7300_i2c_write(struct device *dev, unsigned int reg,
  15. unsigned int val)
  16. {
  17. struct i2c_client *client = to_i2c_client(dev);
  18. return i2c_smbus_write_byte_data(client, reg, val);
  19. }
  20. static int max7300_i2c_read(struct device *dev, unsigned int reg)
  21. {
  22. struct i2c_client *client = to_i2c_client(dev);
  23. return i2c_smbus_read_byte_data(client, reg);
  24. }
  25. static int max7300_probe(struct i2c_client *client,
  26. const struct i2c_device_id *id)
  27. {
  28. struct max7301 *ts;
  29. if (!i2c_check_functionality(client->adapter,
  30. I2C_FUNC_SMBUS_BYTE_DATA))
  31. return -EIO;
  32. ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
  33. if (!ts)
  34. return -ENOMEM;
  35. ts->read = max7300_i2c_read;
  36. ts->write = max7300_i2c_write;
  37. ts->dev = &client->dev;
  38. return __max730x_probe(ts);
  39. }
  40. static int max7300_remove(struct i2c_client *client)
  41. {
  42. return __max730x_remove(&client->dev);
  43. }
  44. static const struct i2c_device_id max7300_id[] = {
  45. { "max7300", 0 },
  46. { }
  47. };
  48. MODULE_DEVICE_TABLE(i2c, max7300_id);
  49. static struct i2c_driver max7300_driver = {
  50. .driver = {
  51. .name = "max7300",
  52. },
  53. .probe = max7300_probe,
  54. .remove = max7300_remove,
  55. .id_table = max7300_id,
  56. };
  57. static int __init max7300_init(void)
  58. {
  59. return i2c_add_driver(&max7300_driver);
  60. }
  61. subsys_initcall(max7300_init);
  62. static void __exit max7300_exit(void)
  63. {
  64. i2c_del_driver(&max7300_driver);
  65. }
  66. module_exit(max7300_exit);
  67. MODULE_AUTHOR("Wolfram Sang");
  68. MODULE_LICENSE("GPL v2");
  69. MODULE_DESCRIPTION("MAX7300 GPIO-Expander");