diff options
author | Bjorn Andersson <bjorn.andersson@sonymobile.com> | 2016-02-18 01:39:04 -0500 |
---|---|---|
committer | Andy Gross <andy.gross@linaro.org> | 2016-03-30 18:20:57 -0400 |
commit | 3fd3f2fd86478614fecbe261b201779b4fc6abd2 (patch) | |
tree | 6d6c1efb72235adffcd074ecdb285612280610db | |
parent | 995b170aeaef4afe0c3469d14b9c80ff2e8a98d7 (diff) |
soc: qcom: smd: Refactor channel open and close handling
Refactor opening and closing of channels into two separate functions
instead of open coding this in the various places.
Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
-rw-r--r-- | drivers/soc/qcom/smd.c | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/drivers/soc/qcom/smd.c b/drivers/soc/qcom/smd.c index e8972ddfee85..d253e5cc233f 100644 --- a/drivers/soc/qcom/smd.c +++ b/drivers/soc/qcom/smd.c | |||
@@ -808,18 +808,12 @@ static int qcom_smd_dev_match(struct device *dev, struct device_driver *drv) | |||
808 | } | 808 | } |
809 | 809 | ||
810 | /* | 810 | /* |
811 | * Probe the smd client. | 811 | * Helper for opening a channel |
812 | * | ||
813 | * The remote side have indicated that it want the channel to be opened, so | ||
814 | * complete the state handshake and probe our client driver. | ||
815 | */ | 812 | */ |
816 | static int qcom_smd_dev_probe(struct device *dev) | 813 | static int qcom_smd_channel_open(struct qcom_smd_channel *channel, |
814 | qcom_smd_cb_t cb) | ||
817 | { | 815 | { |
818 | struct qcom_smd_device *qsdev = to_smd_device(dev); | ||
819 | struct qcom_smd_driver *qsdrv = to_smd_driver(dev); | ||
820 | struct qcom_smd_channel *channel = qsdev->channel; | ||
821 | size_t bb_size; | 816 | size_t bb_size; |
822 | int ret; | ||
823 | 817 | ||
824 | /* | 818 | /* |
825 | * Packets are maximum 4k, but reduce if the fifo is smaller | 819 | * Packets are maximum 4k, but reduce if the fifo is smaller |
@@ -829,11 +823,44 @@ static int qcom_smd_dev_probe(struct device *dev) | |||
829 | if (!channel->bounce_buffer) | 823 | if (!channel->bounce_buffer) |
830 | return -ENOMEM; | 824 | return -ENOMEM; |
831 | 825 | ||
832 | qcom_smd_channel_set_callback(channel, qsdrv->callback); | 826 | qcom_smd_channel_set_callback(channel, cb); |
833 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING); | 827 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING); |
834 | |||
835 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED); | 828 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED); |
836 | 829 | ||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | /* | ||
834 | * Helper for closing and resetting a channel | ||
835 | */ | ||
836 | static void qcom_smd_channel_close(struct qcom_smd_channel *channel) | ||
837 | { | ||
838 | qcom_smd_channel_set_callback(channel, NULL); | ||
839 | |||
840 | kfree(channel->bounce_buffer); | ||
841 | channel->bounce_buffer = NULL; | ||
842 | |||
843 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); | ||
844 | qcom_smd_channel_reset(channel); | ||
845 | } | ||
846 | |||
847 | /* | ||
848 | * Probe the smd client. | ||
849 | * | ||
850 | * The remote side have indicated that it want the channel to be opened, so | ||
851 | * complete the state handshake and probe our client driver. | ||
852 | */ | ||
853 | static int qcom_smd_dev_probe(struct device *dev) | ||
854 | { | ||
855 | struct qcom_smd_device *qsdev = to_smd_device(dev); | ||
856 | struct qcom_smd_driver *qsdrv = to_smd_driver(dev); | ||
857 | struct qcom_smd_channel *channel = qsdev->channel; | ||
858 | int ret; | ||
859 | |||
860 | ret = qcom_smd_channel_open(channel, qsdrv->callback); | ||
861 | if (ret) | ||
862 | return ret; | ||
863 | |||
837 | ret = qsdrv->probe(qsdev); | 864 | ret = qsdrv->probe(qsdev); |
838 | if (ret) | 865 | if (ret) |
839 | goto err; | 866 | goto err; |
@@ -845,11 +872,7 @@ static int qcom_smd_dev_probe(struct device *dev) | |||
845 | err: | 872 | err: |
846 | dev_err(&qsdev->dev, "probe failed\n"); | 873 | dev_err(&qsdev->dev, "probe failed\n"); |
847 | 874 | ||
848 | qcom_smd_channel_set_callback(channel, NULL); | 875 | qcom_smd_channel_close(channel); |
849 | kfree(channel->bounce_buffer); | ||
850 | channel->bounce_buffer = NULL; | ||
851 | |||
852 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); | ||
853 | return ret; | 876 | return ret; |
854 | } | 877 | } |
855 | 878 | ||
@@ -886,12 +909,7 @@ static int qcom_smd_dev_remove(struct device *dev) | |||
886 | * The client is now gone, cleanup and reset the channel state. | 909 | * The client is now gone, cleanup and reset the channel state. |
887 | */ | 910 | */ |
888 | channel->qsdev = NULL; | 911 | channel->qsdev = NULL; |
889 | kfree(channel->bounce_buffer); | 912 | qcom_smd_channel_close(channel); |
890 | channel->bounce_buffer = NULL; | ||
891 | |||
892 | qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); | ||
893 | |||
894 | qcom_smd_channel_reset(channel); | ||
895 | 913 | ||
896 | return 0; | 914 | return 0; |
897 | } | 915 | } |