Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-1.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) //	    S3C2410 bluetooth "driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "gpio-cfg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "regs-gpio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "gpio-samsung.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "h1940.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DRV_NAME "h1940-bt"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /* Bluetooth control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static void h1940bt_enable(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		/* Power on the chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		/* Reset the chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		mdelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		gpio_set_value(S3C2410_GPH(1), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		mdelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		gpio_set_value(S3C2410_GPH(1), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		gpio_set_value(S3C2410_GPH(1), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		mdelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		gpio_set_value(S3C2410_GPH(1), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		mdelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int h1940bt_set_block(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	h1940bt_enable(!blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static const struct rfkill_ops h1940bt_rfkill_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.set_block = h1940bt_set_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int h1940bt_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct rfkill *rfk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		dev_err(&pdev->dev, "could not get GPH1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		gpio_free(S3C2410_GPH(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		dev_err(&pdev->dev, "could not get BT_POWER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* Configures BT serial port GPIOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			&h1940bt_rfkill_ops, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!rfk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		goto err_rfk_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	ret = rfkill_register(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		goto err_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	platform_set_drvdata(pdev, rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) err_rfkill:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	rfkill_destroy(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) err_rfk_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int h1940bt_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct rfkill *rfk = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	platform_set_drvdata(pdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	gpio_free(S3C2410_GPH(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (rfk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		rfkill_unregister(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		rfkill_destroy(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	rfk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	h1940bt_enable(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static struct platform_driver h1940bt_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		.name	= DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	.probe		= h1940bt_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	.remove		= h1940bt_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) module_platform_driver(h1940bt_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) MODULE_LICENSE("GPL");