ese_spi.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2020 Samsung Electronics. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program;
  16. *
  17. */
  18. #include <linux/mutex.h>
  19. #include <linux/printk.h>
  20. #include <linux/spi/spi.h>
  21. #include "ese_spi.h"
  22. #define ERR(msg...) pr_err("[star-spi] : " msg)
  23. #define INFO(msg...) pr_info("[star-spi] : " msg)
  24. int ese_spi_send(void *ctx, unsigned char *buf, unsigned int size)
  25. {
  26. struct spi_device *spidev = ctx;
  27. int ret = 0;
  28. ret = spi_write(spidev, buf, size);
  29. if (ret < 0) {
  30. ERR("failed to write data %d", ret);
  31. return ret;
  32. }
  33. return (int)size;
  34. }
  35. int ese_spi_receive(void *ctx, unsigned char *buf, unsigned int size)
  36. {
  37. struct spi_device *spidev = ctx;
  38. int ret = 0;
  39. ret = spi_read(spidev, (void *)buf, size);
  40. if (ret < 0) {
  41. ERR("failed to read data %d", ret);
  42. return ret;
  43. }
  44. return (int)size;
  45. }