max7300.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * drivers/gpio/max7300.c
  3. *
  4. * Copyright (C) 2009 Wolfram Sang, Pengutronix
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Check max730x.c for further details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/mutex.h>
  16. #include <linux/i2c.h>
  17. #include <linux/spi/max7301.h>
  18. #include <linux/slab.h>
  19. static int max7300_i2c_write(struct device *dev, unsigned int reg,
  20. unsigned int val)
  21. {
  22. struct i2c_client *client = to_i2c_client(dev);
  23. return i2c_smbus_write_byte_data(client, reg, val);
  24. }
  25. static int max7300_i2c_read(struct device *dev, unsigned int reg)
  26. {
  27. struct i2c_client *client = to_i2c_client(dev);
  28. return i2c_smbus_read_byte_data(client, reg);
  29. }
  30. static int __devinit max7300_probe(struct i2c_client *client,
  31. const struct i2c_device_id *id)
  32. {
  33. struct max7301 *ts;
  34. int ret;
  35. if (!i2c_check_functionality(client->adapter,
  36. I2C_FUNC_SMBUS_BYTE_DATA))
  37. return -EIO;
  38. ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
  39. if (!ts)
  40. return -ENOMEM;
  41. ts->read = max7300_i2c_read;
  42. ts->write = max7300_i2c_write;
  43. ts->dev = &client->dev;
  44. ret = __max730x_probe(ts);
  45. if (ret)
  46. kfree(ts);
  47. return ret;
  48. }
  49. static int __devexit max7300_remove(struct i2c_client *client)
  50. {
  51. return __max730x_remove(&client->dev);
  52. }
  53. static const struct i2c_device_id max7300_id[] = {
  54. { "max7300", 0 },
  55. { }
  56. };
  57. MODULE_DEVICE_TABLE(i2c, max7300_id);
  58. static struct i2c_driver max7300_driver = {
  59. .driver = {
  60. .name = "max7300",
  61. .owner = THIS_MODULE,
  62. },
  63. .probe = max7300_probe,
  64. .remove = __devexit_p(max7300_remove),
  65. .id_table = max7300_id,
  66. };
  67. static int __init max7300_init(void)
  68. {
  69. return i2c_add_driver(&max7300_driver);
  70. }
  71. subsys_initcall(max7300_init);
  72. static void __exit max7300_exit(void)
  73. {
  74. i2c_del_driver(&max7300_driver);
  75. }
  76. module_exit(max7300_exit);
  77. MODULE_AUTHOR("Wolfram Sang");
  78. MODULE_LICENSE("GPL v2");
  79. MODULE_DESCRIPTION("MAX7300 GPIO-Expander");